共用方式為


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

更新:2010 年 5 月

叫用函式本身產生選項的選擇性值。

命名空間/模組路徑:Microsoft.FSharp.Core.Option

組件:FSharp.Core (在 FSharp.Core.dll 中)

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

// Usage:
bind binder option

參數

  • binder
    Type: 'T -> 'U option

    函式,採用選項中型別為 T 的值,並將它轉換成含有型別 U 之值的選項。

  • option
    Type: 'T option

    輸入選項。

傳回值

繫結器之輸出型別的選項。

備註

將運算式 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 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本資訊

F# 執行階段

支援版本:2.0、4.0

Silverlight

支援版本:3

請參閱

參考

Core.Option 模組 (F#)

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

變更記錄

日期

History

原因

2010 年 5 月

加入程式碼範例。

資訊加強。