Table of contents
TOC
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 7/8/2016
|
2 Contributors

Evaluates the equivalent of List.exists for an option.

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

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

Syntax

// 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: 'Toption

The input option.

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.

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

Outputtruefalsefalse

Platforms

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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Core.Option Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2016 Microsoft