sequency
Version:
Functional sequences for processing iterable data in JavaScript
41 lines • 1.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlatMap = void 0;
var Sequence_1 = require("./Sequence");
var FlatMapIterator = /** @class */ (function () {
function FlatMapIterator(transform, iterator) {
this.transform = transform;
this.iterator = iterator;
}
FlatMapIterator.prototype.next = function (value) {
if (this.current != null) {
var item = this.current.next();
if (!item.done) {
return item;
}
}
var next = this.iterator.next();
if (!next.done) {
var sequence = this.transform(next.value);
this.current = sequence.iterator;
return this.next();
}
return { done: true, value: undefined };
};
return FlatMapIterator;
}());
var FlatMap = /** @class */ (function () {
function FlatMap() {
}
/**
* Transforms each element into a sequence of items and returns a flat single sequence of all those items.
*
* @param {(value: S) => Sequence<T>} transform
* @returns {Sequence<T>}
*/
FlatMap.prototype.flatMap = function (transform) {
return (0, Sequence_1.createSequence)(new FlatMapIterator(transform, this.iterator));
};
return FlatMap;
}());
exports.FlatMap = FlatMap;
//# sourceMappingURL=flatMap.js.map