Does F# have an equivalent to Haskell's take?

前端 未结 3 1922
野趣味
野趣味 2021-01-01 19:48

In Haskell, there is a function \"take n list\" which returns the first n elements from a list. For example \"sum (take 3 xs)\" sums up the first three elements in the list

3条回答
  •  死守一世寂寞
    2021-01-01 20:12

    Yeah, it's called Seq.take. Usage seems to be identical to Haskell's: Seq.take count source. To use it on a list, use List.toSeq first. (Update: Apparently from the comments, this isn't necessary.)

提交回复
热议问题