List.foldBack2<'T1,'T2,'State> (Función de F#)
Aplica una función a los elementos correspondientes de dos colecciones y subprocesa un argumento acumulador durante el cálculo.Las colecciones deben tener el mismo tamaño.Si la función de entrada es f y los elementos son i0...iN y j0...jN, esta función calcula f i0 j0 (...(f iN jN s)).
Espacio de nombres/Ruta de acceso del módulo: Microsoft.FSharp.Collections.List
Ensamblado: FSharp.Core (en FSharp.Core.dll)
// Signature:
List.foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 list -> 'T2 list -> 'State -> 'State
// Usage:
List.foldBack2 folder list1 list2 state
Parámetros
folder
Tipo: 'T1 -> 'T2 -> 'State -> 'StateFunción que se usa para actualizar el estado asignado a los elementos de entrada.
list1
Tipo: 'T1listaPrimera lista de entrada.
list2
Tipo: 'T2listaSegunda lista de entrada.
state
Tipo: 'StateEstado inicial.
Valor devuelto
Valor de estado final.
Excepciones
Excepción |
Condition |
---|---|
Se produce cuando las listas de entrada tienen longitudes diferentes. |
Comentarios
Esta función se denomina FoldBack2 en los ensamblados compilados.Si obtiene acceso a la función desde un lenguaje .NET distinto de F# o mediante reflexión, use este nombre.
En los ejemplos de código siguientes se muestra la diferencia entre List.fold2 y List.foldBack2.
Ejemplo
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
Output
// 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
Output
Plataformas
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
Información de versiones
Versiones de la biblioteca básica de F#
Se admite en: 2.0, 4.0, portables