Utility functions that aren't in the Signal module from
elm-lang/core.
An alias for andMap. Intended to be paired with the (<~) operator, this
makes it possible for many signals to flow into a function. Think of it as a
fancy alias for mapN. For example, the following declarations are equivalent:
main : Signal Element
main =
scene <~ Window.dimensions ~ Mouse.position
main : Signal Element
main =
map2 scene Window.dimensions Mouse.positionYou can use this pattern for as many signals as you want by using (~) a bunch
of times, so you can go higher than map5 if you need to.
The (<~) operator, but flipped. Doesn't play well with the other
two!
Mouse.x ~> toFloat >> sqrt >> round
>> isEven >> not
>> asTextApply a signal of functions to another signal. Like Task.andMap, this
provides a way to combine several signals together into a data type that's
easier to extend than map2, map3, etc.
type alias User =
{ name : String
, age : Int
, numberOfPosts : Int
}
userSignal : Signal User
userSignal = User
`Signal.map` nameSignal
`andMap` ageSignal
`andMap` numberOfPostsSignalFor 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.
A signal of each change to the provided signal, as a tuple of old and new values.
The initial value of the tuple is the initial value of the provided signal, duplicated. Thereafter, the first part of the tuple is the old value of the provided signal, and the second part is the new value.
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.
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.
The old name for Signal.filter, which doesn't confuse you with what the Bool value means.
The good old keepWhen filter that keeps events from the Signal a as long as the
Signal Bool is true.
A combination of Signal.sampleOn and 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.
Like keepWhen, but when the filter signal turn False, the output
changes back to the base value.
keepWhen but always keeps the initial value rather than trying to
filter it.
Filter a signal of optional values, discarding Nothings.
Apply a fold that may fail, ignore any non-changes.
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) == mergeMerge each Signal in the given list into a given original Signal. This works like Signal.mergeMany, except that it does not crash when given an empty list.
type Update =
MouseMove (Int,Int) | TimeDelta Float | Click
updates : Signal Update
updates =
mergeMany
(MouseMove Mouse.position)
[ map TimeDelta (fps 40)
, map (always Click) Mouse.clicks
]Combine 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 (Maybe comparable)
gives a signal that always carries Just the maximum value from all its
input signals, unless the input signal list is empty, in which case the returned
signal is equivalent to constant Nothing.
Apply functions in a signal to the current value of many signals. The result is reevaluated whenever any signal changes.
Apply a function to the current value of two signals. The second signal is mapped passively -- that is, changes to the second signal do not force the function to re-evaluate. However, when the first signal changes, the function is re-evaluated with the current value of both signals.
This is equivalent to Signal.map2, except that Signal.map2 re-evaluates the function when either Signal changes.
Intended to be paired with Signal's (<~) operator, withPassive makes it
possible for many signals to be passively mapped. For example, the
following two declarations are equivalent:
main : Signal Element
main =
scene <~ Mouse.position `withPassive` Window.dimensions
main : Signal Element
main =
passiveMap2 scene Mouse.position Window.dimensionsYou can use this pattern to passively map as many signals as you want, by using
withPassive many times.
The function will only be re-evaluated when the signal mapped with (<~)
changes. This is unlike the (otherwise equivalent) Signal (~) operator, since
that operator re-evaluates the function whenever any of the input signals change.
If you want the function to be re-evaluated when some signals change but not
others, then you can combine the Signal (~) operator and withPassive, putting
(~) first. For instance:
main : Signal Element
main =
scene <~ Mouse.position ~ Window.dimensions `withPassive` anotherSignalIn this example, the scene function will take three parameters, and will be called
whenever either of the first two parameters changes. The third parameter will
be the value of anotherSignal, but changes to anotherSignal will not cause
the function to be re-evaluated.
An alias for
Signal.map. A prettier way to apply a function to the current value of a signal.