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

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

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

Applies the given function to successive elements, returning the first result where function returns Some for some value. If no such element exists then this function raises System.Collections.Generic.KeyNotFoundException.

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

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


// Signature:
List.pick : ('T -> 'U option) -> 'T list -> 'U

// Usage:
List.pick chooser list


chooser Type: 'T -> 'Uoption

The function to generate options from the elements.

list Type: 'Tlist

The input list.


KeyNotFoundExceptionThrown when a matching element is not found or when the list is empty.

Return Value

The first resulting value where Some is returned.


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


let valuesList = [ ("a", 1); ("b", 2); ("c", 3) ]

let resultPick = List.pick (fun elem ->
                    match elem with
                    | (value, 2) -> Some value
                    | _ -> None) valuesList
printfn "%A" resultPick




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

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft