UNPKG

@klodianimeri/pipejs

Version:

Pipe functions that provide convenient and efficient ways to work with iterators.

13 lines (12 loc) 374 B
import { Pipe } from "../pipe.js"; export function reverse(): Pipe { return () => { let buffer: Array<any> = new Array<any>(); return (result: IteratorResult<any>): Array<IteratorResult<any>> => { if (result?.done) { return [...buffer, result]; } buffer.unshift(result); }; } }