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


Type: 'T -> bool

The function to test the input elements.


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 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0


Supported in: 3

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft