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

Applies the given function to successive elements, returning the first result where function returns Some. If the function never returns Some then KeyNotFoundException is raised.

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

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

// Signature:
Array.pick : ('T -> 'U option) -> 'T [] -> 'U

// Usage:
Array.pick chooser array

Parameters

  • chooser
    Type: 'T -> 'U option

    The function to generate options from the elements.

  • array
    Type: 'T []

    The input array.

Exceptions

Exception

Condition

KeyNotFoundException

Thrown if every result from chooser is None.

Return Value

The first result.

Remarks

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

Example

The following code example shows how to use Array.pick.

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

let resultPick = Array.pick (fun elem ->
                    match elem with
                    | (value, 2) -> Some value
                    | _ -> None) values
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

See Also

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)