What is the reactive network equivalent of flatMap in Haskell's reactive banana?
I'm looking for a function in reactive banana that will select which event stream to emit the next from based on the incoming value of another event stream or signal (Behavior?). In the scala, reactive-web library, this is done with
flatMap[U](f: T => EventStream[U]): EventStream[U]
thank!
source to share
This is a dynamic event switching. Unfortunately, it has a lot of problems in this formulation and therefore is not included in the reaction banana. However, the option of dynamic event switching is coming soon. For now, you will have to do without it.
In particular, flatMap
is the Scala name for the monadic binding function; a Monad
instance for the behavior is problematic as it provides dynamic event triggering functionality that leads to time-out, explained in the linked article.
source to share
As an addition to ehird's answer, I want to mention that it is often possible to avoid switching dynamic events, namely when the corresponding behavior / event types are in scope at compile time. Dynamic event switching is only necessary when calculating a new behavior / event on the fly, not when switching between behavior / events that are already in scope.
In particular, see the TwoCounters.hs example on the examples page to see how you can do this.
source to share