简体   繁体   中英

Bacon.js accumulator

my_Stream is data I want to accumulate and assign to variable for further processing. My question: How do I get the contents of the variable the_string to console.log ONCE THE STREAM IS FINISHED?

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

My full code can be found in github issue page: github.com/nodeschool/discussions/issues/1778

What you want to use is fold , which scans the stream and outputs a value only when the stream ends.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM