共用方式為


Array.foldBack<'T,'State> 函式 (F#)

更新:2010 年 8 月

將函式套用至陣列的每一個元素,以透過計算建立累計值引數的執行緒。 如果輸入函數為 f 而且項目為 i0...iN,則會計算 f i0 (...(f iN s))。

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

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

// Signature:
Array.foldBack : ('T -> 'State -> 'State) -> 'T [] -> 'State -> 'State

// Usage:
Array.foldBack folder array state

參數

  • folder
    型別:'T -> 'State -> 'State

    根據指定的輸入項目更新狀態的函式。

  • array
    Type: 'T []

    輸入陣列。

  • state
    型別:'State

    初始狀態。

傳回值

最終狀態。

備註

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

範例

下列程式碼範例會顯示 的 Array.fold 之間差異 Array.foldBack

// This computes 3 - 2 - 1, which evalates to -6.
let subtractArray array1 = Array.fold (fun acc elem -> acc - elem) 0 array1
printfn "%d" (subtractArray [| 1; 2; 3 |])

// This computes 3 - (2 - (0 - 1)), which evaluates to 2.
let subtractArrayBack array1 = Array.foldBack (fun elem acc -> elem - acc) array1 0
printfn "%d" (subtractArrayBack [| 1; 2; 3 |])

輸出

  

平台

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

請參閱

參考

Collections.Array 模組 (F#)

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

變更記錄

日期

History

原因

2010 年 8 月

加入程式碼範例。

資訊加強。