Question

I'm looking for the function in reactive-banana that will choose from which event stream to emit next depending on the incoming value of another event stream or signal (Behaviour ?). In the library for scala, reactive-web this is done with:

 flatMap[U](f: T => EventStream[U]): EventStream[U] 

thanks !

Was it helpful?

Solution

This is dynamic event switching. Unfortunately, in that formulation, it has many problems, and so is not included in reactive-banana. However, a variant of dynamic event switching will be added soon. For now, you'll have to do without it.

In particular, flatMap is Scala's name for the monadic bind function; a Monad instance for behaviours is problematic because it provides the dynamic event switching functionality that leads to the time leak explained in the article I linked.

OTHER TIPS

As an addendum to ehird's answer, I want to mention that it's often possible to avoid dynamic event switching, namely when the relevant behaviors/events are in scope at compile-time. Dynamic event switching is only needed when you compute a new behavior/event on the fly, not when you switch between behaviors/events that are already in scope.

In particular, have a look at the TwoCounters.hs example on the examples page to see how this can be done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top