List.scanBack<'T,'State> 函式 (F#)
類似 List.foldBack,但會傳回中繼結果和最後結果。
**命名空間/模組路徑:**Microsoft.FSharp.Collections.List
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
List.scanBack : ('T -> 'State -> 'State) -> 'T list -> 'State -> 'State list
// Usage:
List.scanBack folder list state
參數
folder
型別:'T -> 'State -> 'State根據指定的輸入項目更新狀態的函式。
list
型別:'T list輸入清單。
state
型別:'State初始狀態。
傳回值
狀態的清單。
備註
這個函式在已編譯的組件中名為 ScanBack。 如果您是透過 F# 以外的語言,或是透過反映來存取函式,請使用這個名稱。
範例
下列程式碼範例示範如何使用 List.scanBack,也將其行為與 List.scan 進行對比。
// A list of functions that transform
// integers. (int -> int)
let ops1 =
[ (fun x -> x + 1), "add 1"
(fun x -> x + 2), "add 2"
(fun x -> x - 5), "subtract 5" ]
let ops2 =
[ (fun x -> x + 1), "add 1"
(fun x -> x * 5), "multiply by 5"
(fun x -> x * x), "square" ]
// Compare scan and scanBack, which apply the
// operations in the opposite order.
let compareOpOrder ops x0 =
let ops, opNames = List.unzip ops
let xs1 = List.scan (fun x op -> op x) x0 ops
let xs2 = List.scanBack (fun op x -> op x) ops x0
printfn "Operations:"
opNames |> List.iter (fun opName -> printf "%s " opName)
printfn ""
// Print the intermediate results.
let xs = List.zip xs1 (List.rev xs2)
printfn "List.scan List.scanBack"
for (x1, x2) in xs do
printfn "%10d %10d" x1 x2
printfn ""
compareOpOrder ops1 10
compareOpOrder ops2 10
Output
平台
Windows 8 中, Windows 7, Windows Server 2012 上, Windows Server 2008 R2
版本資訊
F# 核心程式庫版本
支援版本:2.0, 4.0,可攜式執行檔 (PE)。