Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
List.partition<'T> Function
Collapse the table of content
Expand the table of content

List.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.List

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

// Signature:
List.partition : ('T -> bool) -> 'T list -> 'T list * 'T list

// Usage:
List.partition predicate list


Type: 'T -> bool

The function to test the input elements.


Type: 'T list

The input list.

A list containing the elements for which the predicate evaluated to false and a list containing the elements for which the predicate evaluated to true.

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 example shows how to use List.partition.

let list1 = [ 1 .. 10 ]
let listEven, listOdd = List.partition (fun elem -> elem % 2 = 0) list1
printfn "Evens: %A\nOdds: %A" listEven listOdd


Evens: [2; 4; 6; 8; 10]
Odds: [1; 3; 5; 7; 9]

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

© 2015 Microsoft