Let's say i'm working with a list like:
let items = [ Some(1); None; Some(8); ];;
What is the shortest means to get only the Some values in the list?
items |> List.filter Option.isSome;;
Is that the quickest? Does using Option.isSome have any drawbacks?
To get the values of all Some instances in a list items :: a option list you can use List.choose:
let values = List.choose id items
this will yield [1; 8] for your example.
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