I'm looking for something like flatten :: Event [a] -> Event a
(swap []
with Foldable f => f
if you want) which would generate a separate event for each a
in an Event
's list, like split
in an old version of sodium
.
I suspect that this is somehow possible with switchE
, but then I'd need a function of type [a] -> Event a
.
I could possibly craft that myself with newEvent
, but is there a function built-in to reactive-banana
?
Edit:
Actually, I'm not so sure I can implement that with newEvent
after all.
flatten :: Foldable f => f a -> Banana.MomentIO (Banana.Event a)
flatten xs = do
(event, fire) <- Banana.newEvent
liftIO $ forkIO $ mapM_ fire xs
return event
Will fire
block until there are subscribers or will it just return immediately if there aren't any?
Edit 2:
Looking at the implementation of newAddHandler
my implementation above won't work, because all events are possibly fired before any handlers can register.
IO
action for each one of thosea
s (fetch/clone git repositories) and then execute downstream code after each one (e.g. build and benchmark the project). I'd prefer to do it in a 'depth-first' (running corresponing fetch and build consecutive) rather than 'breadth-first' manner (running all fetches, then running all builds). There are also other event sources which produce singlea
s, but I could wrap that in singleton lists of course. – Interplay