List.foldBack2<'T1,'T2,'State> — Funkcja (F#)

Dotyczy funkcji odpowiednie elementy zbiorów dwóch wątków argumentu akumulator za pomocą obliczeń.Kolekcje muszą mieć identyczne rozmiarów.Jeśli funkcja wejściowy jest f i elementy są i0...iN i j0...jN, a następnie funkcja oblicza f i0 j0 (...(f iN jN s)).

Ścieżka obszaru nazw/modułu: Microsoft.FSharp.Collections.List

Zestaw: FSharp.Core (w FSharp.Core.dll)

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

// Usage:
List.foldBack2 folder list1 list2 state

Parametry

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

    Funkcja aktualizacji stanu dane wejściowe elementy.

  • list1
    Type: 'T1list

    Pierwsza lista wejściowego.

  • list2
    Type: 'T2list

    Wejściowy drugiej listy.

  • state
    Typ:'State

    Stan początkowy.

Wartość zwracana

Wartość Stan końcowy.

Wyjątki

Wyjątek

Warunek

ArgumentException

Zgłoszony podczas wprowadzania listy różnią się długością.

Uwagi

Ta funkcja o nazwie FoldBack2 w skompilowane zestawy.Jeśli funkcja dostęp z języka .net niż F# lub przez odbicie, należy użyć tej nazwy.

Następujące przykłady kodu ilustrują różnicę między List.fold2 i List.foldBack2.

Przykład

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

Dane wyjściowe

  
// 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

Dane wyjściowe

  

Platformy

Windows 8, Windows 7, Windows Server 2012 Windows Server 2008 R2

Informacje o wersji

F# Core wersji biblioteki

Obsługiwane: 2.0, 4.0, przenośne

Zobacz też

Informacje

Collections.List — Moduł (F#)

Microsoft.FSharp.Collections — Przestrzeń nazw (F#)