Share via


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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reference

Collections.Map Module (F#)

Microsoft.FSharp.Collections Namespace (F#)