Reputation: 19690
This one seems to be a brainer to me. I need to extract x values wrapped into Some(x) from the sequence. I can do it with
xs |> Seq.fold (fun state x -> match x with -> | Some(y) -> y::state | None -> state) []
|> Seq.toList
|> List.rev
|> List.toSeq
Is there a nicer way?
Upvotes: 1
Views: 1138
Reputation: 28745
For a discriminated union that isn't actually the standard Option type, you just need to supply a function to Seq.choose
that takes an instance of your discriminated union and maps it to a standard Option. Something like...
xs |> Seq.choose (function Nothing _ -> None | Something x -> Some x)
Upvotes: 5