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

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

Den Delimarsky|Last Updated: 10/30/2017
|
2 Contributors

Searches the map looking for the first element where the given function returns a Some value. If the function returns None for all elements, raises System.Collections.Generic.KeyNotFoundException.

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

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

Syntax

// Signature:
Map.pick : ('Key -> 'T -> 'U option) -> Map<'Key,'T> -> 'U (requires comparison)

// Usage:
Map.pick chooser table

Parameters

chooser Type: 'Key -> 'T -> 'Uoption

The function to generate options from the key/value pairs.

table Type: Map<'Key,'T>

The input map.

Exceptions

ExceptionCondition
KeyNotFoundExceptionThrown if the function returns None for all elements.

Return Value

The first result.

Remarks

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

Example

The following code shows how to use Map.pick.

let map1 = [ for i in 1 .. 100 -> (i, 100 - i) ] |> Map.ofList
let result = Map.pick (fun key value -> if key = value then Some(key) else None) map1
printfn "Result where key and value are the same: %d" result

Output

Result where key and value are the same: 50

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