UNPKG

axax

Version:

A library of async iterator extensions for JavaScript including ```map```, ```reduce```, ```filter```, ```flatMap```, ```pipe``` and [more](https://github.com/jamiemccrindle/axax/blob/master/docs/API.md#functions).

29 lines (28 loc) 864 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const insert_1 = require("./insert"); const iteratorToIterable_1 = require("./iteratorToIterable"); /** * Lookahead into the async iteratable * * @param source The source iterable to look into * @param howFar How far to look ahead */ function lookahead(howFar) { return async function inner(source) { const iterator = source[Symbol.asyncIterator](); const values = []; for (let i = 0; i < howFar; i++) { const next = await iterator.next(); if (next.done) { break; } values.push(next.value); } return { iterable: insert_1.insert(...values)(iteratorToIterable_1.iteratorToIterable(iterator)), values, }; }; } exports.lookahead = lookahead;