Suppose I have a DU like:
type Fruit =
| Apple of string * bool
| Banana of string
| Cherry of string
Then I have a collection like this:
fruits : Fruit list
I want to pull out all of the Apple
instances to perform some computation:
// apples is Seq<string * bool>
let apples =
fruits
|> Seq.choose (fun x ->
match x with
| Apple a -> Some a
| _ -> None
)
My question is: is there a more concise way to write this?
Something like:
// Not real code
let apples =
fruits
|> Seq.match Apple