共用方式為


Map.tryPick<'Key,'T,'U> 函式 (F#)

搜尋對應,尋找第一個讓指定的函式傳回 Some 值的項目。

命名空間/模組路徑:Microsoft.FSharp.Collections.Map

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

// Signature:
Map.tryPick : ('Key -> 'T -> 'U option) -> Map<'Key,'T> -> 'U option (requires comparison)

// Usage:
Map.tryPick chooser table

參數

  • chooser
    型別:'Key -> 'T -> 'U option

    從索引鍵/值組產生選項的函式。

  • table
    型別:Map<'Key,'T>

    輸入對應。

傳回值

第一個結果。

備註

這個函式在已編譯的組件中名為 TryPick。 如果您是透過 F# 以外的 .NET 語言,或是透過反映來存取函式,請使用這個名稱。

範例

下列程式碼示範 Map.tryPick 函式的用法。

let map1 = [ for i in 1 .. 100 -> (i, 100 - i) ] |> Map.ofList
let result = Map.tryPick (fun key value -> if key = value then Some(key) else None) map1
match result with
| Some x -> printfn "Result where key and value are the same: %d" x
| None -> printfn "No result satisifies the condition."

Output

  

平台

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

版本資訊

F# 核心程式庫版本

支援版本:2.0, 4.0,可攜式執行檔 (PE)。

請參閱

參考

Collections.Map 模組 (F#)

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