UNPKG

iter-tools-es

Version:
38 lines (31 loc) 796 B
const { asyncIterableCurry } = require('../../internal/async-iterable.js'); const { __asyncInterleave } = require('../$interleave/async-interleave.js'); async function* asyncByComparison({ compare }, all, ...peekrs) { let candidate; while (!all.done) { candidate = all.value; for (const peekr of peekrs) { if (!peekr.done && compare(peekr.value, candidate.value) < 0) { candidate = peekr; } } yield candidate.value; await candidate.advance(); } } function __asyncCollate(sources, compare) { return __asyncInterleave(sources, asyncByComparison, { compare }); } exports.__asyncCollate = __asyncCollate; const asyncCollate = /*#__PURE__*/asyncIterableCurry(__asyncCollate, { variadic: true }); exports.asyncCollate = asyncCollate;