This project is read-only.
Using .choose

Category:
Functions - Arrays, Lists, Seqs
Description: .choose applies a given function to the collection, returning an array of results x where the function evaluates to Some(x).
Code:
let AggregateExample5() =
let numbers = seq {1..20}
let evens = Seq.choose(fun x ->
match x with
| x when x%2=0 -> Some(x)
| _ -> None ) numbers
printfn "numbers = %A\n" numbers
printfn "evens = %A" evens

//--------------------------------------------------------

Execution Result:
numbers = seq [1; 2; 3; 4; ...]

evens = seq [2; 4; 6; 8; ...]

Last edited Sep 14, 2011 at 3:54 AM by ttliu2000, version 1

Comments

No comments yet.