UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

27 lines (25 loc) 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.flat = void 0; const flatmap_js_1 = require("./flatmap.js"); const isiterable_js_1 = require("../../util/isiterable.js"); /** * Flattens the nested async-iterable by the given depth. * * @template T The type of elements in the source sequence. * @param {number} [depth=Infinity] The depth to flatten the async-iterable sequence if specified, otherwise infinite. * @returns {MonoTypeOperatorAsyncFunction<T>} An operator that flattens the async-iterable sequence. */ function flat(depth = -1, concurrent = Infinity) { depth = (depth < 0 ? Infinity : depth); return function flattenOperatorFunction(source) { return (0, flatmap_js_1.flatMap)((item) => { if ((0, isiterable_js_1.isAsyncIterable)(item)) { return depth > 0 ? flat(depth - 1)(item) : item; } return [item]; }, concurrent)(source); }; } exports.flat = flat; //# sourceMappingURL=flat.js.map