Array.foldBack2<'T1,'T2,'State> Function (F#)
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
Parameters
folder
Type: 'T1 -> 'T2 -> 'State -> 'StateThe function to update the state given the input elements.
array1
Type: 'T1 []The first input array.
array2
Type: 'T2 []The second input array.
state
Type: 'StateThe initial state.
Exceptions
Exception |
Condition |
---|---|
Thrown when the input arrays differ in length. |
Return Value
The final state.
Remarks
This function is named FoldBack2 in the .NET assembly. If accessing the member from a .NET language other than F#, or through reflection, use this name.
Example
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
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3