2-- The library for general signal manipulation. Some useful functions for
3-- working with time (e.g. setting FPS) and combining signals and time (e.g.
4-- delaying updates, getting timestamps) can be found in the
5-- [`Time`](/docs/Signal/Time.elm) library.
7-- Note: There are lift functions up to `lift8`.
10import Native.Signal as Native
12-- Create a constant signal that never changes.
13constant : a -> Signal a
15-- Transform a signal with a given function.
16lift : (a -> b) -> Signal a -> Signal b
18-- Combine two signals with a given function.
19lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
21-- Combine three signals with a given function.
22lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
23lift4 : (a -> b -> c -> d -> e) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e
24lift5 : (a -> b -> c -> d -> e -> f) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f
25lift6 : (a -> b -> c -> d -> e -> f -> g) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g
26lift7 : (a -> b -> c -> d -> e -> f -> g -> h) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h
27lift8 : (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h -> Signal i
29-- Create a past-dependent signal. Each value given on the input signal will
30-- be accumulated, producing a new output value.
32-- For instance, `(foldp (\\t acc -> acc + 1) 0 (Time.every second))` increments every second.
33foldp : (a -> b -> b) -> b -> Signal a -> Signal b
35-- Merge two signals into one, biased towards the first signal if both signals
36-- update at the same time.
37merge : Signal a -> Signal a -> Signal a
39-- Merge many signals into one, biased towards the left-most signal if multiple
40-- signals update simultaneously.
41merges : [Signal a] -> Signal a
43-- Merge two signals into one, but distinguishing the values by marking the first
44-- signal as `Left` and the second signal as `Right`. This allows you to easily
45-- fold over non-homogeneous inputs.
46mergeEither : Signal a -> Signal b -> Signal (Either a b)
48-- Count the number of events that have occured.
49count : Signal a -> Signal Int
51-- Count the number of events that have occured that satisfy a given predicate.
52countIf : (a -> Bool) -> Signal a -> Signal Int
54-- Keep only events that satisfy the given predicate. Elm does not allow
55-- undefined signals, so a base case must be provided in case the predicate is
57keepIf : (a -> Bool) -> a -> Signal a -> Signal a
59-- Drop events that satisfy the given predicate. Elm does not allow undefined
60-- signals, so a base case must be provided in case the predicate is never
62dropIf : (a -> Bool) -> a -> Signal a -> Signal a
64-- Keep events only when the first signal is true. When the first signal becomes
65-- true, the most recent value of the second signal will be propagated. Until
66-- the first signal becomes false again, all events will be propagated. Elm does
67-- not allow undefined signals, so a base case must be provided in case the first
68-- signal is never true.
69keepWhen : Signal Bool -> a -> Signal a -> Signal a
71-- Drop events when the first signal is true. When the first signal becomes false,
72-- the most recent value of the second signal will be propagated. Until the first
73-- signal becomes true again, all events will be propagated. Elm does not allow
74-- undefined signals, so a base case must be provided in case the first signal is
76dropWhen : Signal Bool -> a -> Signal a -> Signal a
78-- Drop sequential repeated values. For example, if a signal produces the
79-- sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that
80-- are the same as the previous value.
81dropRepeats : Signal a -> Signal a
83-- Sample from the second input every time an event occurs on the first input.
84-- For example, `(sampleOn clicks (every second))` will give the approximate
85-- time of the latest click.
86sampleOn : Signal a -> Signal b -> Signal b
88-- Add a timestamp to any signal. Timestamps increase monotonically. Each timestamp is
89-- related to a specfic event, so `Mouse.x` and `Mouse.y` will always have the same
90-- timestamp because they both rely on the same underlying event.
91timestamp : Signal a -> Signal (Time, a)
93-- Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
94-- will update one second later than any mouse click.
95delay : Time -> Signal a -> Signal a
97{-- TODO: only found in docs
98 , ("average", "Int -> Signal Number -> Signal Float", [markdown|
100Takes an integer `n` and a signal of numbers. Computes the running
101average of the signal over the last `n` events.
103So `(average 20 (fps 40))` would be the average time between the frames for
104the last 20 frames.|])
105 , ("foldp1", "(a -> a -> a) -> Signal a -> Signal a", [markdown|
106Create a past-dependent signal. The first value on the signal is used
108 , ("foldp'", "(a -> b -> b) -> (a -> b) -> Signal a -> Signal b", [markdown|
109Just like foldp, but instead of a base case, you provide a function to be
110applied to the first value, creating the base case.|])
111 [ ("(<~)", "(a -> b) -> Signal a -> Signal b", [markdown|
112An alias for `lift`. A prettier way to apply a
113function to the current value of a signal.|])
114 , ("(~)", "Signal (a -> b) -> Signal a -> Signal b", [markdown|
115Signal application. This takes two signals, holding a function and
116a value. It applies the current function to the current value.
118So the following expressions are equivalent:
120 scene <~ Mouse.x ~ Mouse.y
121 lift2 scene Mouse.x Mouse.y|])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list