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

Map.partition<'Key,'T> Function (F#)

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

Creates two new maps, one containing the bindings for which the given predicate returns true, and the other the remaining bindings.

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

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

Syntax

// Signature:
Map.partition : ('Key -> 'T -> bool) -> Map<'Key,'T> -> Map<'Key,'T> * Map<'Key,'T> (requires comparison)

// Usage:
Map.partition predicate table

Parameters

predicate Type: 'Key -> 'T ->bool

The function to test the input elements.

table Type: Map<'Key,'T>

The input map.

Return Value

A pair of maps in which the first contains the elements for which the predicate returned true and the second containing the elements for which the predicated returned 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


let map1 = [ for i in 1..10 -> (i, i*i)] |> Map.ofList
let (mapEven, mapOdd) = Map.partition (fun key value -> key % 2 = 0) map1
printfn "Evens: %A" mapEven
printfn "Odds: %A" mapOdd

Output

Evens: map [(2, 4); (4, 16); (6, 36); (8, 64); (10, 100)]
Odds: map [(1, 1); (3, 9); (5, 25); (7, 49); (9, 81)]

Platforms

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.Map Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2018 Microsoft