f# - Why there is no List.skip and List.take? -
why there no list.skip , list.take? there of course seq.take , seq.skip, not create lists result.
one possible solution is: mylist |> seq.skip n |> seq.tolist creates first enumerator new list enumerator. think there more direct way create immutable list immutable list. since there no copying of elements internally there references new list original one.
other possible solution (without throwing exceptions) is:
let rec listskip n xs = match (n, xs) | 0, _ -> xs | _, [] -> [] | n, _::xs -> listskip (n-1) xs
but still not answer question...
the would-be list.skip 1
called list.tail
, can tail
list n times.
list.take
have create new list anyway, since common suffixes of immutable list can shared.
Comments
Post a Comment