Standard Array.filter logic for the iterable, extended with iteration state + async.
In the example below, we take advantage of the IterationState, to detect and remove repeated values (do not confuse with distinct, which removes all duplicates).
import {pipe, filter} from 'iter-ops';
const i = pipe(
iterable,
filter((value, index, state) => {
if(value === state.previousValue) {
return false;
}
state.previousValue = value;
return true;
})
);
Note that the predicate can only return a Promise
inside an asynchronous pipeline,
or else the Promise
will be treated as a truthy value.
Standard Array.filter logic for the iterable, extended with iteration state.
In the example below, we are able to use a type guard to filter out all the nullable values.
Note: The asynchronous version of this function cannot make use of type guards.
Give a :+1: to the Asynchronous Type Guards issue if you want support for this.