Bacon.Observable.prototype.waterfall = function(f){
var children = this.map(f).flatMap(function(x){ return x.waterfall(f); });
return this.merge(children);
}
I've found it to be useful in game programming. It's sort of a recursive application of flatMap, where the main stream can spawn child streams, its children can spawn more streams, and so on. For example: http://jsfiddle.net/N4DeQ/1/
Is there a standard name for this pattern? If it doesn't already have a name, can you help me think of a good name for it?
Bonus question: this combinator seems to only work when I add 'delay(0)' before invoking it (see: http://jsfiddle.net/N4DeQ/2/). Why is that? Can I make this work without the delay(0)? Is Bacon behaving correctly in this case?