Reputation: 95
I am working on a project using Helm, which is based on the Elm language.
I need to trigger an event based on which signal out of a pair of signals arrives first. In Elm, I would use the merge function, but I cannot find an equivalent in Helm. The closest I see is combine (in the signal library), which doesn't appear to do what I want. It seems that combine just takes a list of signals and makes them directly into a signal of lists, which is not quite what I'm looking for.
EDIT: specifically I am looking for a function with signature Signal a -> Signal a -> Signal a
that takes the first signal to fire and discards the second.
What's the best way to accomplish this in Helm?
Upvotes: 4
Views: 126
Reputation: 5958
I think the best way would be finding out how Helm's Signal
s are implemented in terms of Elerea's stuff, and implementing merge
in those more primitive terms. I'm afraid I can't help you there, because I don't know Helm well and I don't know Elerea at all.
I can help you with a hacky solution based solely on Helm. You can use timestamp
to distinguish different events from zipped signals:
merge sigL sigR =
let
tsMerge (t1,v1) (t2,v2) =
if t1 >= t2
then v1
else v2
in
tsMerge <~ timestamp sigL ~~ timestamp sigR
Upvotes: 2
Reputation: 14485
You can combine things using the Applicative
instance. For example liftA2 (,)
will have type Signal a -> Signal b -> Signal (a,b)
.
(I'm not 100% sure if this is your question, though. If your question is about merging events like Event a -> Event a -> Event a
, I'm not sure helm has features like that. I can only find the documentation for behavior-like Signal
s that have continuous semantics.)
Upvotes: 2