I have a list like [1..12]
and I would like to get a piece like [4..9]
. No clue how I can do that, I'm new with F#. I don't know if there is a built-in method for that, but I would like to know the manual way.
[1..12] |> List.filter (fun x -> x >= 4 && x <= 9)
or
[1..12] |> Seq.skip 3 |> Seq.take 6 |> Seq.toList
Lists don't support slicing, but if you use an array instead you can also do this:
[|1..12|].[3..8]
(note 3..8 instead of 4..9 because of 0-based indexing)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With