Skip to content

unfoldAsync

unfoldAsync<S, T>(seed, next): AsyncIterableIterator<T>

Defined in: packages/core/src/iterable/async/unfold.ts:17

Generates a sequence from a seed, one step at a time — the dual of reduce.

The async counterpart of unfold, and the shape a paginated API has: the state is the cursor, and next resolves to the page plus the cursor that follows it, or undefined when there are no more.

Time complexity: O(1) per element, plus whatever next costs.

S

T

S

The initial state.

MaybeAsyncCallable<[S], readonly [T, S] | undefined>

Receives the current state and resolves to [value, nextState], or undefined to end the sequence.

AsyncIterableIterator<T>

An iterator over the generated values.