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

省略可能な値に対して関数を呼び出します。これ自体はオプションになります。

名前空間/モジュール パス: Microsoft.FSharp.Core.Option

アセンブリ: FSharp.Core (FSharp.Core.dll)

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

// Usage:
bind binder option

パラメーター

  • binder
    型: 'T -> 'Uoption

    オプションから型 T の値を受け取り、型 U の値を格納するオプションに変換する関数。

  • option
    型: 'Toption

    入力オプション。

戻り値

バインダーの出力型のオプション。

解説

式 Option.bind f inp は match inp with None -> None | Some x -> f x. に評価されます。

この関数は、コンパイルされたアセンブリでは Bind という名前です。F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

次のコードは、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

出力

  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

Core.Option モジュール (F#)

Microsoft.FSharp.Core 名前空間 (F#)