Please explain why the below stream overflows?
infiniteStream = function(page) {
return Bacon.fromBinder(function(sink) {
sink(page);
sink(new Bacon.Next(function() { return infiniteStream(page + 1); }));
}).flatMapConcat(function(v) {
return v;
});
};
fiveStream = function(count) {
return Bacon.fromArray([count, count, count, count, count]);
};
stream = infiniteStream(1).flatMapConcat(function(v) {
return fiveStream(v);
});
// fine
stream.take(6).log();
// Error: maximum call stack exceeded
stream.take(7).log();
I need an infinite stream, I can map to some values, I want to use take(10)
to pull as needed, or I want to end this stream whenever some specific value is reached, eg:
stream = stream.withHandler(function(v) {
if (v.hasValue() && v.value() == "link50") {
this.push(new Bacon.Error("bad link"));
return this.push(new Bacon.End());
} else {
return this.push(v);
}
});