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

Option.bind<'T,'U> Function (F#)

Den Delimarsky|Last Updated: 8/18/2017
2 Contributors

Invokes a function on an optional value that itself yields an option.

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

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


// Signature:
bind : ('T -> 'U option) -> 'T option -> 'U option

// Usage:
bind binder option


binder Type: 'T -> 'Uoption

A function that takes the value of type T from an option and transforms it into an option containing a value of type U.

option Type: 'Toption

The input option.

Return Value

An option of the output type of the binder.


The expression Option.bind f inp evaluates to match inp with None -> None | Some x -> f x.

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


let stringOpt1 = Some("Mirror Image")
let stringOpt2 = None
let reverse (string : System.String) =
    match string with
    | "" -> None
    | s -> Some(new System.String(string.ToCharArray() |> Array.rev))
let result1 = Option.bind reverse stringOpt1
printfn "%A" result1
let result2 = Option.bind reverse stringOpt2
printfn "%A" result2


Some "egamI rorriM"<null>


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#)

© 2020 Microsoft