@@ -7,46 +7,64 @@
77-- Note: There are lift functions up to `lift8`.
88module Signal where
99
10−import Native.Signal as S
11−import List as L
10+import Native.Signal as Native
11+import List (foldr)
1212
1313-- Create a constant signal that never changes.
1414constant : a -> Signal a
15+constant = Native.constant
1516
1617-- Transform a signal with a given function.
1718lift : (a -> b) -> Signal a -> Signal b
19+lift = Native.lift
1820
1921-- Combine two signals with a given function.
2022lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
23+lift2 = Native.lift2
2124
2225-- Combine three signals with a given function.
2326lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
27+lift3 = Native.lift3
28+
2429lift4 : (a -> b -> c -> d -> e) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e
30+lift4 = Native.lift4
31+
2532lift5 : (a -> b -> c -> d -> e -> f) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f
33+lift5 = Native.lift5
34+
2635lift6 : (a -> b -> c -> d -> e -> f -> g)
2736 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g
37+lift6 = Native.lift6
38+
2839lift7 : (a -> b -> c -> d -> e -> f -> g -> h)
2940 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h
41+lift7 = Native.lift7
42+
3043lift8 : (a -> b -> c -> d -> e -> f -> g -> h -> i)
3144 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h -> Signal i
45+lift8 = Native.lift8
46+
3247
3348-- Create a past-dependent signal. Each value given on the input signal will
3449-- be accumulated, producing a new output value.
3550--
3651-- For instance, `(foldp (\\t acc -> acc + 1) 0 (Time.every second))` increments every second.
3752foldp : (a -> b -> b) -> b -> Signal a -> Signal b
53+foldp = Native.foldp
3854
3955-- Merge two signals into one, biased towards the first signal if both signals
4056-- update at the same time.
4157merge : Signal a -> Signal a -> Signal a
58+merge = Native.merge
4259
4360-- Merge many signals into one, biased towards the left-most signal if multiple
4461-- signals update simultaneously.
4562merges : [Signal a] -> Signal a
63+merges = Native.merges
4664
4765-- Combine a list of signals into a signal of lists.
4866combine : [Signal a] -> Signal [a]
49−combine = L.foldr (S.lift2 (::)) (S.constant [])
67+combine = foldr (Native.lift2 (::)) (Native.constant [])
5068
5169 -- Merge two signals into one, but distinguishing the values by marking the first
5270 -- signal as `Left` and the second signal as `Right`. This allows you to easily
@@ -55,19 +73,23 @@ combine = L.foldr (S.lift2 (::)) (S.constant [])
5573
5674-- Count the number of events that have occured.
5775count : Signal a -> Signal Int
76+count = Native.count
5877
5978-- Count the number of events that have occured that satisfy a given predicate.
6079countIf : (a -> Bool) -> Signal a -> Signal Int
80+countIf = Native.countIf
6181
6282-- Keep only events that satisfy the given predicate. Elm does not allow
6383-- undefined signals, so a base case must be provided in case the predicate is
6484-- never satisfied.
6585keepIf : (a -> Bool) -> a -> Signal a -> Signal a
86+keepIf = Native.keepIf
6687
6788-- Drop events that satisfy the given predicate. Elm does not allow undefined
6889-- signals, so a base case must be provided in case the predicate is never
6990-- satisfied.
7091dropIf : (a -> Bool) -> a -> Signal a -> Signal a
92+dropIf = Native.dropIf
7193
7294-- Keep events only when the first signal is true. When the first signal becomes
7395-- true, the most recent value of the second signal will be propagated. Until
@@ -75,6 +97,7 @@ dropIf : (a -> Bool) -> a -> Signal a -> Signal a
7597-- not allow undefined signals, so a base case must be provided in case the first
7698-- signal is never true.
7799keepWhen : Signal Bool -> a -> Signal a -> Signal a
100+keepWhen = Native.keepWhen
78101
79102-- Drop events when the first signal is true. When the first signal becomes false,
80103-- the most recent value of the second signal will be propagated. Until the first
@@ -82,22 +105,26 @@ keepWhen : Signal Bool -> a -> Signal a -> Signal a
82105-- undefined signals, so a base case must be provided in case the first signal is
83106-- always true.
84107dropWhen : Signal Bool -> a -> Signal a -> Signal a
108+dropWhen = Native.dropWhen
85109
86110-- Drop sequential repeated values. For example, if a signal produces the
87111-- sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that
88112-- are the same as the previous value.
89113dropRepeats : Signal a -> Signal a
114+dropRepeats = Native.dropRepeats
90115
91116-- Sample from the second input every time an event occurs on the first input.
92117-- For example, `(sampleOn clicks (every second))` will give the approximate
93118-- time of the latest click.
94119sampleOn : Signal a -> Signal b -> Signal b
120+sampleOn = Native.sampleOn
95121
96122-- An alias for `lift`. A prettier way to apply a
97123-- function to the current value of a signal.
98124--
99125-- lift f signal == f <~ signal
100126(<~) : (a -> b) -> Signal a -> Signal b
127+(<~) = Native.lift
101128
102129-- Signal application. This takes two signals, holding a function and
103130-- a value. It applies the current function to the current value.
@@ -107,3 +134,4 @@ sampleOn : Signal a -> Signal b -> Signal b
107134-- scene <~ Window.dimensions ~ Mouse.position
108135-- lift2 scene Window.dimensions Mouse.position
109136(~) : Signal (a -> b) -> Signal a -> Signal b
137+(~) = Native.lift2 (\f x -> f x)