Option.foldBack<'T,'State> Function (F#)
Performs the equivalent of the List.foldBack operation on an option.
Namespace/Module Path: Microsoft.FSharp.Core.Option
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
foldBack : ('T -> 'State -> 'State) -> 'T option -> 'State -> 'State
// Usage:
foldBack folder option state
Parameters
folder
Type: 'T -> 'State -> 'StateA function to update the state data when given a value from an option.
option
Type: 'T optionThe input option.
state
Type: 'StateThe initial state.
Return Value
If the option is None, it returns the initial value of state. Otherwise, it returns the updated state, the result of applying the folder function with the option value and the initial state.
Remarks
The expression fold f inp s evaluates to match inp with None -> s | Some x -> f x s.
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 illustrates the use of Option.foldBack.
let consOption list opt =
Option.foldBack (fun value state -> value :: state) list opt
printfn "%A" <| consOption None [ 1 .. 10 ]
printfn "%A" <| consOption (Some(0)) [1 .. 10]
Output
[1; 2; 3; 4; 5; 6; 7; 8; 9; 10] [0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
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