Aracılığıyla paylaş


List.foldBack2<'T1,'T2,'State> İşlevi (F#)

Bir işlevi iki koleksiyonun öğelerine accumulator bağımsız değişken hesaplama iş parçacığı ile uygular. Koleksiyonların boyutunun aynı olması gerekir. Giriş işlevi ise, f ve öğeleri, i0...iN ve j0...jN, sonra da bu işlevi hesaplar f i0 j0 (...(f iN jN s)).

Ad alanı/modül yolu: Microsoft.FSharp.Collections.List

Derleme: 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

Parametreler

  • folder
    Türü:'T1 -> 'T2 -> 'State -> 'State

    Verilen giriş öğelerine göre durumu güncellemek için işlev.

  • list1
    Type: 'T1list

    İlk giriş listesi.

  • list2
    Type: 'T2list

    İkinci giriş listesi.

  • state
    Türü:'State

    Başlangıç durumu.

Dönüş Değeri

Son durum değeri.

Özel Durumlar

Özel Durum

Koşul

ArgumentException

Giriş listelerinin uzunluğunu farklı olduğu zaman oluşturulur.

Notlar

Bu işlev adlı FoldBack2 kodları derlenmiş derlemeleri. İşlev .net Dili dışındaki F# veya yansıtma üzerinden erişiyorsanız, bu adı kullanın.

Aşağıdaki kod örnekleri arasındaki farkı gösteren List.fold2 ve List.foldBack2.

Örnek

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

Çıktı

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

Çıktı

  

Platformlar

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

Sürüm Bilgisi

F# Çekirdek Kitaplığı sürümleri

Desteklenen: 2.0, 4.0, Portable

Ayrıca bkz.

Başvuru

Collections.List Modülü (F#)

Microsoft.FSharp.Collections İsim Uzayı (F#)