Expand Minimize

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

Splits the collection into two collections, containing the elements for which the given predicate returns true and false respectively.

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

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

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

// Usage:
Array.partition predicate array

predicate

Type: 'T -> bool

The function to test the input elements.

array

Type: 'T []

The input array.

A pair of arrays. The first containing the elements the predicate for which the predicate evaluated to true, and the second containing those for which the predicate evaluated to false.

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

The following code illustrates the use of Array.partition.

let removeOutliers array1 min max =
    Array.partition (fun elem -> elem > min && elem < max) array1
    |> fst
removeOutliers [| 1 .. 100 |] 50 60
|> printf "%A"

Output

[|51; 52; 53; 54; 55; 56; 57; 58; 59|]

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft