UNPKG

@idealic/poker-engine

Version:

Professional poker game engine and hand evaluator with built-in iterator utilities

41 lines 1.23 kB
/** * Functions for transforming elements of an iterable using a mapper function */ import { pubsub } from './lib/pubsub'; /** * Internal implementation of async map * * @param input Source iterable to map over * @param iteratorFn Function to transform each item */ async function* _map(input, iteratorFn) { for await (const value of input) { yield await iteratorFn(value, input); } } /** * Process an iterable with limited concurrency * * @param input Source iterable to map over * @param iteratorFn Function to apply to each item in the iterable * @param concurrency Maximum number of map operations */ function _mapConcurrently(iterator, iteratorFn, concurrency) { const { output, input } = pubsub(concurrency); // dont allow input stream to block the main loop return output({ onStart: () => input(iterator, iteratorFn), }); } export function map(input, transform, concurrency) { if (typeof input === 'function') { return (_input) => map(_input, input, transform); } else if (concurrency > 1) { return _mapConcurrently(input, transform, concurrency); } else { return _map(input, transform); } } //# sourceMappingURL=map.js.map