You have difficulty defining zipE because it does not make semantic meaning. If you consider semantic definitions
Event a == [(Time, a)] Event b == [(Time, b)]
There is no natural way to zip them, because usually each event will be at a different time.
You can fix them using the amount instead of the product.
zipE :: Event a -> Event b -> Event (Either ab) zipE aE bE = (Left <$> aE) `mappend` (Right <$> bE)
If you really need to have both a and b at the same time, a suitable solution is to create a Behavior that accumulates over a particular stream, or a combined Either stream, as described above.
edit: an example of one accumulation method over a merged stream (unchecked). Other implementations are possible. This does not cause both events to happen at the same time; rather, it allows you to combine the current state with past states so that you can always have the most recent left and Right values available.
currentAandB :: a -> b -> Event a -> Event b -> Event (a,b) currentAandB a0 b0 aE bE = accumE (a0,b0) (mergefn <$> zipE aE bE) where mergefn (Left a) (_,b) = (a,b) mergefn (Right b) (a,_) = (a,b)
It is still necessary to specify the initial values for the Event streams. Think of it this way: if you only had events from Event a , what value should the second part of the tuple have?
John l
source share