@reactivex/ix-es5-esm
Version:
The Interactive Extensions for JavaScript
25 lines (23 loc) • 953 B
JavaScript
import { flatMap } from './flatmap.js';
import { isAsyncIterable } from '../../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.
*/
export function flat(depth, concurrent) {
if (depth === void 0) { depth = -1; }
if (concurrent === void 0) { concurrent = Infinity; }
depth = (depth < 0 ? Infinity : depth);
return function flattenOperatorFunction(source) {
return flatMap(function (item) {
if (isAsyncIterable(item)) {
return depth > 0 ? flat(depth - 1)(item) : item;
}
return [item];
}, concurrent)(source);
};
}
//# sourceMappingURL=flat.js.map