@klodianimeri/pipejs
Version:
Pipe functions that provide convenient and efficient ways to work with iterators.
18 lines (14 loc) • 451 B
text/typescript
import { Pipe } from "../pipe.js";
export function filter(predicate: (element: any, index?: number) => boolean): Pipe {
return () => {
let i: number = -1;
return (result: IteratorResult<any>): IteratorResult<any> => {
++i;
if (result?.done) {
return result;
}
if (!predicate(result.value, i)) return;
return result;
};
}
}