Map.foldBack<'Key,'T,'State> Function (F#)

Folds over the bindings in the map.

Namespace/Module Path: Microsoft.FSharp.Collections.Map

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

// Signature:
Map.foldBack : ('Key -> 'T -> 'State -> 'State) -> Map<'Key,'T> -> 'State -> 'State (requires comparison)

// Usage:
Map.foldBack folder table state

Parameters

  • folder
    Type: 'Key -> 'T -> 'State -> 'State

    The function to update the state given the input key/value pairs.

  • table
    Type: Map<'Key,'T>

    The input map.

  • state
    Type: 'State

    The initial state.

Return Value

The final state value.

Remarks

This function is named FoldBack in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

Example

The following code shows how to use Map.foldBack.

let map1 = Map.ofList [ (1, "one"); (2, "two"); (3, "three") ]
// Sum the keys.
let result1 = Map.foldBack (fun key value state -> state + key) map1 0
printfn "Result: %d" result1
// Concatenate the values.
let result2 = Map.foldBack (fun key value state -> state + value + " ") map1 ""
printfn "Result: %s" result2 

Output

Result: 6
Result: three two one

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

See Also

Reference

Collections.Map Module (F#)

Microsoft.FSharp.Collections Namespace (F#)