Array.foldBack2<'T1,'T2,'State> Function (F#)
Visual Studio 2012
Apply a function to pairs of elements drawn from the two collections, right-to-left, threading an accumulator argument through the computation. The two input arrays must have the same lengths, otherwise an ArgumentException is raised.
Namespace/Module Path: Microsoft.FSharp.Collections.Array
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Array.foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 [] -> 'T2 [] -> 'State -> 'State
// Usage:
Array.foldBack2 folder array1 array2 state
The following code shows how to use 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
Output
Ending balance: $1205.00