Array.foldBack2<'T1,'T2,'State> 函式 (F#)
更新:2010 年 8 月
將函式套用至從兩個集合繪製的項目組 (從右到左),以透過計算建立累計值引數的執行緒。 這兩個輸入陣列的長度必須相同,否則會引發 ArgumentException。
命名空間/模組路徑: Microsoft.FSharp.Collections.Array
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
Array.foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 [] -> 'T2 [] -> 'State -> 'State
// Usage:
Array.foldBack2 folder array1 array2 state
參數
folder
型別:'T1 -> 'T2 -> 'State -> 'State根據指定的輸入項目更新狀態的函式。
array1
型別:'T1 []第一個輸入陣列。
array2
型別:'T2 []第二個輸入陣列。
state
型別:'State初始狀態。
例外狀況
例外狀況 |
條件 |
---|---|
當輸入陣列的長度不同時擲回。 |
傳回值
最終狀態。
備註
這個函式在 .NET 組件中名為 FoldBack2。 如果是透過 F# 以外的 .NET 語言存取成員,或透過反映存取成員,請使用這個名稱。
範例
下列程式碼顯示如何使用 Array.foldBack2
type Transaction =
| Deposit
| Withdrawal
let transactionTypes = [| Deposit; Deposit; Withdrawal |]
let transactionAmounts = [| 100.00; 1000.00; 95.00 |]
let initialBalance = 200.00
let endingBalance = Array.foldBack2 (fun elem1 elem2 acc ->
match elem1 with
| Deposit -> acc + elem2
| Withdrawal -> acc - elem2)
transactionTypes
transactionAmounts
initialBalance
printfn "Ending balance: $%.2f" endingBalance
輸出
平台
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
請參閱
參考
Microsoft.FSharp.Collections 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2010 年 8 月 |
加入程式碼範例。 |
資訊加強。 |