UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

48 lines 1.62 kB
import toIterator from '../toIterator'; import isIterable from '../isIterable'; import isIterator from '../isIterator'; /** Maps and flattens an iterator by a depth of 1. */ var FlatMapIterator = /** @class */ (function () { function FlatMapIterator(iterator, iteratee) { this.iterator = iterator; this.iteratee = iteratee; this.inner = null; } FlatMapIterator.prototype[Symbol.iterator] = function () { return this; }; FlatMapIterator.prototype.next = function () { var _a, _b; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (this.inner) { var next_1 = (_a = this.inner).next.apply(_a, args); if (next_1.done) { this.inner = null; return this.next.apply(this, args); } return next_1; } var next = (_b = this.iterator).next.apply(_b, args); if (next.done) return next; var value = this.iteratee(next.value); if (typeof value !== 'string') { if (isIterator(value)) { this.inner = value; return this.next.apply(this, args); } else if (isIterable(value)) { this.inner = toIterator(value); return this.next.apply(this, args); } } return { value: value, done: false }; }; return FlatMapIterator; }()); export { FlatMapIterator }; export default FlatMapIterator; //# sourceMappingURL=FlatMapIterator.js.map