Option.exists<'T> Function (F#)

Evaluates the equivalent of List.exists for an option.

Namespace/Module Path: Microsoft.FSharp.Core.Option

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

// Signature:
exists : ('T -> bool) -> 'T option -> bool

// Usage:
exists predicate option

Parameters

  • predicate
    Type: 'T -> bool

    A function that evaluates to a Boolean when given a value from the option type.

  • option
    Type: 'T option

    The input option.

Return Value

Returns false if the option is None, otherwise it returns the result of applying the predicate to the option value.

Remarks

The expression exists p inp evaluates to match inp with None -> false | Some x -> p x.

This function is named Exists 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 illustrates the use of Option.exists.

let isValue opt value =
    Option.exists (fun elem -> elem = value) opt
let testOpt1 = Some(10)
let testOpt2 = Some(11)
let testOpt3 = None
printfn "%b" <| isValue testOpt1 10
printfn "%b" <| isValue testOpt2 10
printfn "%b" <| isValue testOpt3 10

Output

true
false
false

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

Core.Option Module (F#)

Microsoft.FSharp.Core Namespace (F#)