Utility functions that aren't in the Signal module from
elm-lang/core.
For those too lazy to write a record or union type.
Zip two signals into a signal of pairs.
zip Mouse.x Mouse.y == Mouse.positionUnzip a signal of pairs to a pair of signals.
unzip Mouse.position == (Mouse.x, Mouse.y)foldp' is slighty more general than foldp in that you can base
the initial value of the state on the initial value of the input value.
foldp f b s == foldp' f (always b) sLike foldp, but with a hidden state
foldp f b i ==
let d a = (a,a) -- doubling function
in foldps (\a b -> f a b |> d) (d b) iLike foldp', but with a hidden state
A running buffer of the given size (n) of the given signal.
The list of at most n of the last values on the input signal. Starts
with an empty list. Adds new values to the end of the list! So you get
a list with time going from left to right.
((==) [1,2,3,4,5]) <~ runBuffer 5 (count (Time.every second))Same as runBuffer but with an initial buffer.
Instead of delaying for some amount of time, delay for one round,
where a round is initiated by outside event to the Elm program.
This may not be be very useful yet. Let the package author know if you
find a good use!
Also known to delay in E-FRP.
A combination of Signal.sampleOn and Signal.keepWhen. When the
first signal becomes True, the most recent value of the second signal
will be propagated.
Before Elm 0.12
this was the standard behaviour of keepWhen.
Switch between two signals. When the first signal is True, use the
second signal, otherwise use the third.
Same as the previous, but samples the signal it switches to.
Like keepWhen, but when the filter signal turn False, the output
changes back to the base value.
A function that merges the events of two signals without bias
(unlike Signal.merge). It takes a resolution function for the
(usually rare) case that the signals update in the same "round".
fairMerge (\l r -> l) == mergeCombine a list of signals into a signal of lists. We have
combine = mapMany identityAlso, whenever you are in a situation where you write something like
Signal.map f (combine signals)you are better off directly using mapMany f signals.
Apply a function to the current value of many signals. The function is reevaluated whenever any signal changes. A typical use case:
mapMany (flow down) [sig_elem1, sig_elem2, sig_elem3]Note how this is nicer (and more extendable) than the equivalent:
Signal.map3 (\e1 e2 e3 -> flow down [e1, e2, e3]) sig_elem1 sig_elem2 sig_elem3Also, mapMany List.maximum : List (Signal comparable) -> Signal comparable
gives a signal that always carries the maximum value from all its
input signals.
The
(<~)operator, but flipped. Doesn't play well with the other two!