To manage a dynamic collection of behaviors, you have to use dynamic event switching. See the BarTab.hs example for a demonstration.
However, dynamic event switching can be a bit unwieldy and it is often possible to avoid it. Two common situations are:
- The collection of behaviors is known statically. The TwoCounters.hs demonstrates that one can simply use the applicative functor combinators to calculate a value depending on either behavior.
- The dynamic collection can be modeled as a behavior of a collection (
Behavior [a]
) as opposed to a collection of behaviors ([Behavior a]
). The Asteroids.hs example demonstrates how to use this. This is a stylistic trade-off: the individual entries of the collection cannot be formulated with FRP anymore, but the collection becomes easier to manage.