Bacon.js 累加器

Bacon.js accumulator

my_Stream 是我要累积并分配给变量以供进一步处理的数据。我的问题:如何在流结束后将变量 the_string 的内容获取到 console.log?

my_Stream.onValue(function(value) {
 the_string = the_string.concat(value);
});

我的完整代码可以在 github 问题页面中找到:github.com/nodeschool/discussions/issues/1778

你要使用的是fold,它扫描流并仅在流结束时输出一个值。

const stream = Bacon.sequentially(100, ["Hello", "world"])    
stream.log("stream")
const concatenated = stream.fold("", (a,b) => a + b)
concatenated.log("concatenated")

http://jsbin.com/yodudiqovi/edit?html,js,console