FoldBack

Creates a new TState value by applying the given folder function to state and Option<T>.Some option value. Otherwise returns the state itself.

Parameters

Returns

Func<T, TState, TState> folder

Option<T> option

TState state

TState

Usage

This function applies the folder function to the Option<T> value and to the state.

When the optional value IsNone the folder function won't be executed and the state is returned as a result.

This function is similar to Fold, the only difference between these two functions are the parameters order and the parameters order of the folder function.

When the option value IsSome

int state = 30
Option<int> optionValue = 10;
int result = optionValue.FoldBack(
                (value, _state) => value + _state,
                state);

//result = 40

Last updated