Splitting a list of items into two lists of odd and even indexed items

前端 未结 8 2085
悲&欢浪女
悲&欢浪女 2020-12-11 00:56

I would like to make a function that accepts a list and returns two lists: the first contains every odd item, and the second contains every even item.

For example, g

8条回答
  •  爱一瞬间的悲伤
    2020-12-11 01:47

    Implementation which does not stack-overflows:

    let splitList list = List.foldBack (fun x (l,r) -> x::r, l) list ([],[])
    

提交回复
热议问题