List.foldBack2<'T1,'T2,'State> 関数 (F#)

計算にアキュムレータ引数を使用しながら、2 つのコレクションの対応する要素に関数を適用します。各コレクションは同じサイズである必要があります。入力関数が f で、要素が i0...iN および j0...jN の場合は、f i0 j0 (...(f iN jN s)) を計算します。

名前空間/モジュール パス: Microsoft.FSharp.Collections.List

アセンブリ: FSharp.Core (FSharp.Core.dll 内)

// Signature:
List.foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 list -> 'T2 list -> 'State -> 'State

// Usage:
List.foldBack2 folder list1 list2 state

パラメーター

  • folder
    型: 'T1 -> 'T2 -> 'State -> 'State

    入力要素を受け取って状態を更新する関数。

  • list1
    型: 'T1list

    最初の入力リスト。

  • list2
    型: 'T2list

    2 番目の入力リスト。

  • state
    型: 'State

    初期状態です。

戻り値

最終状態の値。

例外

例外

状態

ArgumentException

入力リストの長さが異なる場合にスローされます。

解説

この関数は、コンパイルされたアセンブリでは FoldBack2 という名前です。F# 以外の .NET 言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

List.fold2List.foldBack2 の違いを次のコード例に示します。

使用例

type Transaction2 =
    | Deposit
    | Withdrawal
    | Interest

let transactionTypes2 = [Deposit; Deposit; Withdrawal; Interest]
let transactionAmounts2 = [100.00; 1000.00; 95.00; 0.05 / 12.0 ]
let initialBalance2 = 200.00

// Because fold2 processes the lists by starting at the head element,
// the interest is calculated last, on the balance of 1205.00.
let endingBalance2 = List.fold2 (fun acc elem1 elem2 ->
                                match elem1 with
                                | Deposit -> acc + elem2
                                | Withdrawal -> acc - elem2
                                | Interest -> acc * (1.0 + elem2))
                                initialBalance2
                                transactionTypes2
                                transactionAmounts2
printfn "%f" endingBalance2

出力

  
// Because foldBack2 processes the lists by starting at end of the list,
// the interest is calculated first, on the balance of only 200.00.
let endingBalance3 = List.foldBack2 (fun elem1 elem2 acc ->
                                match elem1 with
                                | Deposit -> acc + elem2
                                | Withdrawal -> acc - elem2
                                | Interest -> acc * (1.0 + elem2))
                                transactionTypes2
                                transactionAmounts2
                                initialBalance2
printfn "%f" endingBalance3

出力

  

プラットフォーム

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

バージョン情報

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

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

参照

関連項目

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

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