共用方式為


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

建立兩個新的對應,其中一個包含讓所指定述詞傳回 true 的繫結,而另一個則包含其餘的繫結。

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

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

// Signature:
Map.partition : ('Key -> 'T -> bool) -> Map<'Key,'T> -> Map<'Key,'T> * Map<'Key,'T> (requires comparison)

// Usage:
Map.partition predicate table

參數

  • predicate
    型別:'Key -> 'T -> bool

    用來測試輸入項目的函式。

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

    輸入對應。

傳回值

成對的對應,第一個對應包含述詞傳回 true 的項目,第二個對應則包含述詞傳回 false 的項目。

備註

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

範例

下列程式碼示範如何使用 Map.partition

let map1 = [ for i in 1..10 -> (i, i*i)] |> Map.ofList
let (mapEven, mapOdd) = Map.partition (fun key value -> key % 2 = 0) map1
printfn "Evens: %A" mapEven
printfn "Odds: %A" mapOdd

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