I am new to reactive banana and FRP in general, so apologies if I am missing something obvious.
For my project (a GDB/MI front-end) I am using reactive banana (version 0.6.0.0) for both the GUI and the front-end logic modules. The former works great but for the latter I apparently need additional combinators.
One of them is zipE :: Event t a -> Event t b -> Event t (a, b)
. Unfortunately, all I could come up with is a solution in the NetworkDescription monad that uses changes
and is not generic in the event types:
zipE :: Event t Int -> Event t String -> NetworkDescription t (Event t (Int, String))
zipE ea eb = changes $ (,) <$> stepper 0 ea <*> stepper "" eb
Of course, I am not satisfied with this. Thus I wanted to ask how to implement a generic zipE function without using changes
(which is discouraged to use for non-GUI purposes).
Other attempts failed, e.g.
zipE :: Num a => Event t a -> Event t b -> Event t (a,b)
zipE ea eb = apply (stepper (0,) ((,) <$> ea)) eb
results in the first elements of the tuples being shifted by one - I guess due to the "slight delay" introduced by stepper
. But I don't see how to obtain a behavior from an event without stepper
(or accumB
for that matter) and I don't see how to apply a function to an event without a behavior. And overall, I don't see how to provide an initial value to stepper in case of a generic type.
ea
andeb
are not going to fire at the same time. (If you know they're going to fire at the same time because they're both derived from the same underlying event, it's probably best to reprocess that underlying event.) What do you want to happen when one fires and the other doesn't? – Linagef :: (a,b) -> IO ()
. What I have now instead isf :: a -> b -> IO ()
andreactimate $ (f <$> stepper 0 aE) <@> bE
. – Alsoran