Iter Pipe allows you to define custom iterator functions. This exists for Synchronous iterators as well.
import { Iter } from '@j-cake/jcake-utils/iter';
for await (const i of Iter([1, 2, 3, 4, 5, 6, 7, 8])
.pipe(async function* (nums: AsyncIterable<number>, window) {
const buf: number[] = [];
for await (const num of nums) {
buf.push(num);
if (buf.length === window)
yield buf.splice(0, buf.length);
}
}, 2)
console.log(i);
// [1, 2]
// [3, 4]
// [5, 6]
// [7, 8]
What's Changed
- v1.2.0-r0 by @J-Cake in #3
- Merge pull request #3 from J-Cake/parse by @J-Cake in #4
- Parse by @J-Cake in #5
- Added iter pipe by @J-Cake in #7
Full Changelog: v1.1.4...v1.2.1