How to combine two or more signals in elerea?

Is there something like a reactive-bananas union in elerea ?

 union :: Signal a -> Signal a -> Signal a 

It simply combines two signals into one stream. Ideally, I am looking for efficient combining of a large number of signals (14k):

 unions :: [Signal a] -> Signal a 

There should be nothing in the documents, and there is nothing that I could recognize as its building block.


Edit: except maybe this:

 unionSignal :: a -> Signal a -> Signal a -> SignalGen p (Signal a) unionSignal initial ab = do (s,f) <- execute $ external initial _ <- effectful1 fa _ <- effectful1 fb return s 

But ... it is just ugly and does not reflect the idea of union .

+7
haskell frp elerea
source share
1 answer

There is nothing like union for an elerea signal because of how the elerea network is modeled. The elerea signal contains exactly one value at each step, so there is no reasonable way to combine arbitrary values ​​at the same time. However, there are several different ways to combine signals, depending on how you combine the values.

 unions :: [Signal a] -> Signal [a] unions = sequence -- or Data.Traversable.sequenceA 

or you can stack directly through the entrances

 foldS :: (a -> b -> b) -> b -> [Signal a] -> Signal b foldS fb signals = foldr (\signal acc -> f <$> signal <*> acc) (return b) signals -- I think a right fold is more efficient, but it depends on elerea internals and I'm not sure 

If you really don't care about the value and just want to make sure the signal is on, you can use

 unions_ :: [Signal a] -> Signal () unions_ = sequence_ 
+4
source share

All Articles