Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 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
Parameters
chooser
Type: 'T -> 'U optionThe function to generate options from the elements.
list
Type: 'T listThe input list.
Exceptions
Exception |
Condition |
---|---|
Thrown when a matching element is not found or when the list is empty. |
Return Value
The first resulting value where Some is returned.
Remarks
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.
Example
The following code example illustrates the use of List.pick.
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
Output
"b"
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