Lists and Choose

Category:
Lists, Tuples and Options
Description: Project from a list
Code:
let ListSample7() =
let data = [("Cats",4);
("Dogs",5);
("Mice",3);
("Elephants",2)]
let res = data |> List.choose (fun (nm,x) -> if nm.Length <= 4 then Some(x) else None)
printfn "Counts of animals with short names: %A" res


Execution Result:
Counts of animals with short names: [4; 5; 3]

Last edited Sep 14, 2011 at 2:51 AM by ttliu2000, version 1

Comments

No comments yet.