Using .filter

Category:
Functions - Arrays, Lists, Seqs
Description: .filter applies a given function to the collection, returning only those elements for which the given predicate returns true.
Code:
let AggregateExample4() =
let names = [|"Bob"; "Jim"; "Stephen"; "James"; "Fred"; "Will"; "Brian"; "David"; "Mark"; "Jonathan"|]
let longNames = Array.filter (fun (x: string) -> x.Length > 4) names

printfn "names = %A\n" names
printfn "longNames = %A" longNames

Execution Result:
names = [|"Bob"; "Jim"; "Stephen"; "James"; "Fred"; "Will"; "Brian"; "David"; "Mark";
"Jonathan"|]

longNames = [|"Stephen"; "James"; "Brian"; "David"; "Jonathan"|]

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

Comments

No comments yet.