UNPKG

@klodianimeri/pipejs

Version:

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

19 lines (16 loc) 529 B
import { Pipe } from "../pipe.js"; export function skipLast(count: number): Pipe { count = (typeof count === "number" && count > 0) ? count : 0; return () => { let items: Array<any> = new Array<any>(); return (result: IteratorResult<any>): IteratorResult<any> => { if (result?.done) { return result; } items.push(result); if (items.length > count) { return items.shift(); } }; } }