Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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


Type: 'T -> bool

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


Type: 'T option

The input option.

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

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.

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



Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0


Supported in: 3

Community Additions

© 2015 Microsoft