MoreEnumerableUnfoldTState, T, TResult Method

Returns a sequence generated by applying a state to the generator function, and from its result, determines if the sequence should have a next element, its value, and the next state in the recursive call.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<TResult> Unfold<TState, T, TResult>(
	TState state,
	Func<TState, T> generator,
	Func<T, bool> predicate,
	Func<T, TState> stateSelector,
	Func<T, TResult> resultSelector
)

Parameters

state  TState
The initial state.
generator  FuncTState, T
Function that takes a state and computes the next state and the next element of the sequence.
predicate  FuncT, Boolean
Function to determine if the unfolding should continue based the result of the generator function.
stateSelector  FuncT, TState
Function to select the state from the output of the generator function.
resultSelector  FuncT, TResult
Function to select the result from the output of the generator function.

Type Parameters

TState
Type of state elements.
T
Type of the elements generated by the generator function.
TResult
The type of the elements of the result sequence.

Return Value

IEnumerableTResult
A sequence containing the results generated by the resultSelector function.

Remarks

This operator uses deferred execution and streams its results.

See Also