Add topic_generator.map().

This commit is contained in:
Steve Howell
2017-04-21 08:26:40 -07:00
committed by Tim Abbott
parent bdcddd35d0
commit d332df8cc6
2 changed files with 19 additions and 0 deletions

View File

@@ -61,6 +61,13 @@ function is_odd(i) { return i % 2 === 1; }
assert.equal(gen.next(), undefined); assert.equal(gen.next(), undefined);
assert.equal(gen.next(), undefined); assert.equal(gen.next(), undefined);
ints = tg.list_generator([10, 20, 30]);
function mult10(x) { return x * 10; }
gen = tg.map(ints, mult10);
assert.equal(gen.next(), 100);
assert.equal(gen.next(), 200);
}()); }());
(function test_fchain() { (function test_fchain() {

View File

@@ -110,6 +110,18 @@ exports.filter = function (gen, filter_func) {
}; };
}; };
exports.map = function (gen, map_func) {
return {
next: function () {
var val = gen.next();
if (val === undefined) {
return;
}
return map_func(val);
},
};
};
exports.next_topic = function (streams, get_topics, has_unread_messages, curr_stream, curr_topic) { exports.next_topic = function (streams, get_topics, has_unread_messages, curr_stream, curr_topic) {
var stream_gen = exports.wrap(streams, curr_stream); var stream_gen = exports.wrap(streams, curr_stream);