This topic has not yet been rated - Rate this topic

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
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.

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

Output

true
false
false

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.