UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

39 lines (37 loc) 1.08 kB
import { IterableX } from '../iterablex'; import { isIterable } from '../../util/isiterable'; export class FlattenIterable extends IterableX { constructor(source, depth) { super(); this._source = source; this._depth = depth; } // eslint-disable-next-line consistent-return *_flatten(source, depth) { if (depth === 0) { for (const item of source) { yield item; } return undefined; } for (const item of source) { if (isIterable(item)) { for (const innerItem of this._flatten(item, depth - 1)) { yield innerItem; } } else { yield item; } } } [Symbol.iterator]() { return this._flatten(this._source, this._depth)[Symbol.iterator](); } } export function flat(depth = Infinity) { return function flattenOperatorFunction(source) { return new FlattenIterable(source, depth); }; } //# sourceMappingURL=flat.mjs.map