UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

61 lines (59 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.map = exports.MapAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("../asynciterablex.js"); const withabort_js_1 = require("./withabort.js"); const aborterror_js_1 = require("../../aborterror.js"); /** @ignore */ class MapAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(source, selector, thisArg) { super(); this._source = source; this._selector = selector; this._thisArg = thisArg; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { var _b, e_1, _c, _d; (0, aborterror_js_1.throwIfAborted)(signal); let i = 0; try { for (var _e = true, _f = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._source, signal)), _g; _g = yield tslib_1.__await(_f.next()), _b = _g.done, !_b; _e = true) { _d = _g.value; _e = false; const item = _d; const result = yield tslib_1.__await(this._selector.call(this._thisArg, item, i++, signal)); yield yield tslib_1.__await(result); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_e && !_b && (_c = _f.return)) yield tslib_1.__await(_c.call(_f)); } finally { if (e_1) throw e_1.error; } } }); } } exports.MapAsyncIterable = MapAsyncIterable; /** * Projects each element of an async-enumerable sequence into a new form. * * @template TSource The type of the elements in the source sequence. * @template TResult The type of the elements in the result sequence, obtained by running the selector * function for each element in the source sequence. * @param {((value: TSource, index: number, signal?: AbortSignal) => Promise<TResult> | TResult)} selector A transform function * to apply to each source element. * @param {*} [thisArg] Optional this for binding to the selector. * @returns {OperatorAsyncFunction<TSource, TResult>} An async-iterable sequence whose elements are the result of invoking the transform * function on each element of source. */ function map(selector, thisArg) { return function mapOperatorFunction(source) { return new MapAsyncIterable(source, selector, thisArg); }; } exports.map = map; //# sourceMappingURL=map.js.map