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.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.0.0
Syntax 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
)
Public Shared Function Unfold(Of TState, T, TResult) (
state As TState,
generator As Func(Of TState, T),
predicate As Func(Of T, Boolean),
stateSelector As Func(Of T, TState),
resultSelector As Func(Of T, TResult)
) As IEnumerable(Of TResult)
public:
generic<typename TState, typename T, typename TResult>
static IEnumerable<TResult>^ Unfold(
TState state,
Func<TState, T>^ generator,
Func<T, bool>^ predicate,
Func<T, TState>^ stateSelector,
Func<T, TResult>^ resultSelector
)
static member Unfold :
state : 'TState *
generator : Func<'TState, 'T> *
predicate : Func<'T, bool> *
stateSelector : Func<'T, 'TState> *
resultSelector : Func<'T, 'TResult> -> IEnumerable<'TResult>
Parameters
- state
- Type: TState
The initial state. - generator
- Type: SystemFuncTState, T
Function that takes a state and computes the next state and the next element of the sequence.
- predicate
- Type: SystemFuncT, Boolean
Function to determine if the unfolding should continue based the
result of the generator function.
- stateSelector
- Type: SystemFuncT, TState
Function to select the state from the output of the generator function.
- resultSelector
- Type: SystemFuncT, 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
Type:
IEnumerableTResultA sequence containing the results generated by the
resultSelector function.
Remarks
This operator uses deferred execution and streams its results.
See Also