Share via


Funzione List.scanBack<'T,'State> (F#)

Analogo a List.foldBack, ma restituisce sia i risultati intermedi che quelli finali.

Percorso di spazio dei nomi/modulo: Microsoft.FSharp.Collections.List

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
List.scanBack : ('T -> 'State -> 'State) -> 'T list -> 'State -> 'State list

// Usage:
List.scanBack folder list state

Parametri

  • folder
    Tipo: 'T -> 'State -> 'State

    Funzione da utilizzare per aggiornare lo stato in base agli elementi di input.

  • list
    Tipo: 'Tlist

    Elenco di input.

  • state
    Tipo: 'State

    Stato iniziale.

Valore restituito

Elenco di stati.

Note

Questa funzione è denominata ScanBack negli assembly compilati.Utilizzare questo nome se si accede alla funzione da un linguaggio diverso da F# o tramite reflection.

Esempio

Nell'esempio di codice riportato di seguito viene illustrato come utilizzare List.scanBack e ne viene inoltre confrontato il comportamento con List.scan..

// A list of functions that transform 
// integers. (int -> int)
let ops1 =
 [ (fun x -> x + 1), "add 1"
   (fun x -> x + 2), "add 2"
   (fun x -> x - 5), "subtract 5" ]

let ops2 =
 [ (fun x -> x + 1), "add 1"
   (fun x -> x * 5), "multiply by 5"
   (fun x -> x * x), "square" ]

// Compare scan and scanBack, which apply the
// operations in the opposite order.
let compareOpOrder ops x0 =
    let ops, opNames = List.unzip ops
    let xs1 = List.scan (fun x op -> op x) x0 ops
    let xs2 = List.scanBack (fun op x -> op x) ops x0

    printfn "Operations:"
    opNames |> List.iter (fun opName -> printf "%s  " opName)
    printfn ""

    // Print the intermediate results.
    let xs = List.zip xs1 (List.rev xs2)
    printfn "List.scan List.scanBack"
    for (x1, x2) in xs do
        printfn "%10d %10d" x1 x2
    printfn ""

compareOpOrder ops1 10
compareOpOrder ops2 10

Output

  

Piattaforme

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

Informazioni sulla versione

Versioni della libreria di base F#

Supportato in: 2,0, 4,0, portabile

Vedere anche

Riferimenti

Modulo Collections.List (F#)

Spazio dei nomi Microsoft.FSharp.Collections (F#)