Help me name this combinator

50 views
Skip to first unread message

mkaemmerer

unread,
Jul 23, 2014, 1:22:50 PM7/23/14
to bac...@googlegroups.com
I wrote a new(?) combinator:

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?

pavelp...@gmail.com

unread,
Feb 16, 2015, 7:54:54 AM2/16/15
to bac...@googlegroups.com
Dne středa 23. července 2014 19:22:50 UTC+2 mkaemmerer napsal(a):
I guess I'm late to the party. But thanks a lot for this function! I could not implement it correctly myself, but I need just it! :-) As to the name, I could not find a matching signature on Hoogle, so I judge that it is not that common. In my use-case, I only ever use a streams with a single value as a return of `f`, and as `this`, so in my case it seems to be similar to Haskell's `iterate`. I'm naming it `iterate` in my codebase :)
Reply all
Reply to author
Forward
0 new messages