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
    型: 'Tlist

    入力リスト。

  • 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

出力

  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

Collections.List モジュール (F#)

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