I would like use a wire of type Wire s e m a b
to handle multiple inputs. The intended semantics would be
- If the input list is
[]
do nothing and return an empty list - If the input list is
a:as
step the wire with inputa
, recursively step the resulting wire with inputas
, and then collect the results into a list
Is this a sensible thing to do? Is my implementation sensible? Inhibitions are completely ignored here, which seems strange. What is the right way to create wires that handle "multiple events at once" in netwire?
many :: (Monoid s, Monad m) => Wire s e m a b -> Wire s e m [a] [b]
many w = mkGen (\s as -> do
(bs, w') <- go s w as
return (Right bs, many w'))
where go _ w' [] = return ([], w')
go s w' (a:as) = do
(e, w'') <- stepWire w' s (Right a)
(bs, w''') <- go s w'' as
let b = case e of Right r -> [r]
Left _ -> []
return (b ++ bs, w''')