Export (0) Print
Expand All
Expand Minimize

Array.filter<'T> Function (F#)

Returns a new collection containing only the elements of the collection for which the given predicate returns true.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Array.filter : ('T -> bool) -> 'T [] -> 'T []

// Usage:
Array.filter predicate array

predicate

Type: 'T -> bool

The function to test the input elements.

array

Type: 'T []

The input array.

An array containing the elements for which the given predicate returns true.

This function is named Filter in compiled assemblies. If accessing the function from a language other than F#, or through reflection, use this name.

The following example shows how to use Array.filter to select elements from an array.

let names = [|"Bob"; "Ann"; "Stephen"; "Vivek"; "Fred"; "Kim"; "Brian"; "Ling"; "Jane"; "Jonathan"|]
let longNames = names |> Array.filter (fun x -> x.Length > 4)

printfn "names = %A\n" names
printfn "longNames = %A" longNames
names = [|"Bob"; "Ann"; "Stephen"; "Vivek"; "Fred"; "Kim"; "Brian"; "Ling"; "Jane"; "Jonathan"|]

longNames = [|"Stephen"; "Vivek"; "Brian"; "Jonathan"|]

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Show:
© 2014 Microsoft