mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
Add topic_generator.map().
This commit is contained in:
@@ -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() {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user