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
Parameters
predicate
Type: 'T -> boolThe 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.
Remarks
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.
Example
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|]
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3