Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Option.bind<'T,'U> Function (F#)

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

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


Type: 'T -> 'U option

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


Type: 'T option

The input option.

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.

The following code illustrates the use of Option.bind.

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"

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

© 2015 Microsoft