on master help sign in
Add combine to the signal library.
commitd27ab15ec46aac955715591ff8f0e4bd2b4a84e2 authorevancz <info@elm-lang.org> dateWed 3 Apr 2013, 09:54 (14 years ago) parent1dbbc59
1 file changed+19−18
libraries/Signal.elm+19−18
libraries/Signal.elm+19−18
@@ -7,7 +7,8 @@
77-- Note: There are lift functions up to `lift8`.
88module Signal where
99
10−import Native.Signal as Native
10+import Native.Signal as S
11+import List as L
1112
1213-- Create a constant signal that never changes.
1314constant : a -> Signal a
@@ -40,6 +41,9 @@ merge : Signal a -> Signal a -> Signal a
4041-- signals update simultaneously.
4142merges : [Signal a] -> Signal a
4243
44+combine : [Signal a] -> Signal [a]
45+combine = List.foldr (S.lift2 (::)) (S.constant [])
46+
4347-- Merge two signals into one, but distinguishing the values by marking the first
4448-- signal as `Left` and the second signal as `Right`. This allows you to easily
4549-- fold over non-homogeneous inputs.
@@ -94,6 +98,20 @@ timestamp : Signal a -> Signal (Time, a)
9498-- will update one second later than any mouse click.
9599delay : Time -> Signal a -> Signal a
96100
101+-- An alias for `lift`. A prettier way to apply a
102+-- function to the current value of a signal.
103+(<~) : (a -> b) -> Signal a -> Signal b
104+
105+-- Signal application. This takes two signals, holding a function and
106+-- a value. It applies the current function to the current value.
107+--
108+-- So the following expressions are equivalent:
109+--
110+-- scene <~ Mouse.x ~ Mouse.y
111+-- lift2 scene Mouse.x Mouse.y
112+(~) : Signal (a -> b) -> Signal a -> Signal b
113+
114+
97115{-- TODO: only found in docs
98116 , ("average", "Int -> Signal Number -> Signal Float", [markdown|
99117
@@ -102,22 +120,5 @@ average of the signal over the last `n` events.
102120
103121So `(average 20 (fps 40))` would be the average time between the frames for
104122the last 20 frames.|])
105− , ("foldp1", "(a -> a -> a) -> Signal a -> Signal a", [markdown|
106−Create a past-dependent signal. The first value on the signal is used
107−as the base case.|])
108− , ("foldp'", "(a -> b -> b) -> (a -> b) -> Signal a -> Signal b", [markdown|
109−Just like foldp, but instead of a base case, you provide a function to be
110−applied to the first value, creating the base case.|])
111− [ ("(<~)", "(a -> b) -> Signal a -> Signal b", [markdown|
112−An alias for `lift`. A prettier way to apply a
113−function to the current value of a signal.|])
114− , ("(~)", "Signal (a -> b) -> Signal a -> Signal b", [markdown|
115−Signal application. This takes two signals, holding a function and
116−a value. It applies the current function to the current value.
117−
118−So the following expressions are equivalent:
119−
120− scene <~ Mouse.x ~ Mouse.y
121− lift2 scene Mouse.x Mouse.y|])
122123--}
123124