haskellreactive-banana

Unzip an event stream of tuple 2 into two streams


In reactive-banana, given Event t (a, b), how would you lead it to (Event t a, Event t b)?

Traversable#sequence seems to solve it with some instance of Monad for (,) provided, but Event t is only Functor.


Solution

  • This should work:

    import Control.Applicative
    
    unzipEvent :: Event t (a, b) -> (Event t a, Event t b)
    unzipEvent = liftA2 (,) (fmap fst) (fmap snd)
    

    Notes: