Skip to content

Iteration State

Vitaly Tomilov edited this page Sep 28, 2022 · 27 revisions

Most operators that take a callback function, support state (of type IterationState), as the last callback parameter.

It is there to help with special processing logic, when the callback needs to keep intermediate processing data.

Example:

const i = pipe(
    iterable,
    filter((value, index, state) => {
        // state = {} / empty object, persisted through the iteration session of the operator,
        // so you can change the processing logic, based on the state.
    })
);
Clone this wiki locally