Table of contents
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

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.

Return Value

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"


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


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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft