on master help sign in
Migrate type annotations to more JS files.
b4dba5fevancz
core-js/Char.js+40
@@ -1,3 +1,43 @@
1+/*! Char !*/
2+
3+/*[Classification]*/
4+
5+/** isUpper : Char -> Bool
6+ Selects upper case letters.
7+**/
8+/** isLower : Char -> Bool
9+ Selects lower case letters.
10+**/
11+/** isDigit : Char -> Bool
12+ Selects ASCII digits (0..9).
13+**/
14+/** isOctDigit : Char -> Bool
15+ Selects ASCII octal digits (0..7).
16+**/
17+/** isHexDigit : Char -> Bool
18+ Selects ASCII hexadecimal digits (0..9a..fA..F).
19+**/
20+
21+/*[Conversion]*/
22+
23+/** toUpper : Char -> Char
24+ Convert to upper case.
25+**/
26+/** toLower : Char -> Char
27+ Convert to lower case.
28+**/
29+/** toLocaleUpper : Char -> Char
30+ Convert to upper case, according to any locale-specific case mappings.
31+**/
32+/** toLocaleLower : Char -> Char
33+ Convert to lower case, according to any locale-specific case mappings.
34+**/
35+/** toCode : Char -> Int
36+ Convert to unicode.
37+**/
38+/** fromCode : Int -> Char
39+ Convert from unicode.
40+**/
1
41
2Elm.Char = function() {
42Elm.Char = function() {
3 function isBetween(lo,hi) { return function(chr) {
43 function isBetween(lo,hi) { return function(chr) {
core-js/Either.js+44
@@ -1,19 +1,63 @@
1+/*! Either
2+!*/
3+
1
4
2Elm.Either = function() {
5Elm.Either = function() {
6+ /*[Definition]*/
7+
8+ /** data Either a b = Left a | Right b
9+ Represents any data that can take two different types.
10+
11+ This can also be used for error handling (`Either String a`) where
12+ error messages are stored on the left, and the correct values
13+ ("right" values) are stored on the right.
14+ **/
3 function Left(a1) { return ['Left',a1]; }
15 function Left(a1) { return ['Left',a1]; }
4 function Right(a1){ return ['Right',a1]; }
16 function Right(a1){ return ['Right',a1]; }
17+
18+ /*[Basics]*/
19+
20+ /** either : (a -> c) -> (b -> c) -> Either a b -> c
21+ Apply the first function to a `Left` and the second function to a `Right`.
22+ This allows the extraction of a value from an `Either`.
23+ **/
5 function either(f){ return function(g){ return function(e){
24 function either(f){ return function(g){ return function(e){
6 switch(e[0]){
25 switch(e[0]){
7 case 'Left': return f(e[1]);
26 case 'Left': return f(e[1]);
8 case 'Right': return g(e[1]);
27 case 'Right': return g(e[1]);
9 }
28 }
10 };};}
29 };};}
30+
31+ /** isLeft : Either a b -> Bool
32+ True if the value is a `Left`.
33+ **/
11 function isLeft(e) { return e[0] == 'Left'; }
34 function isLeft(e) { return e[0] == 'Left'; }
35+
36+ /** isRight : Either a b -> Bool
37+ True if the value is a `Right`.
38+ **/
12 function isRight(e) { return e[0] == 'Right'; }
39 function isRight(e) { return e[0] == 'Right'; }
13
40
41+ /*[With Lists]*/
42+
14 function get(es) { return Elm.List.map(function(x){return x[1];})(es); }
43 function get(es) { return Elm.List.map(function(x){return x[1];})(es); }
44+
45+ /** lefts : [Either a b] -> [a]
46+ Keep only the values held in `Left` values.
47+ **/
15 function lefts(es) { return get(Elm.List.filter(isLeft)(es)); }
48 function lefts(es) { return get(Elm.List.filter(isLeft)(es)); }
49+
50+ /** rights : [Either a b] -> [a]
51+ Keep only the values held in `Right` values.
52+ **/
16 function rights(es) { return get(Elm.List.filter(isRight)(es)); }
53 function rights(es) { return get(Elm.List.filter(isRight)(es)); }
54+
55+ /** partition : [Either a b] -> ([a],[b])
56+ Split into two lists, lefts on the left and rights on the right.
57+ So we have the equivalence:
58+
59+ partition es == (lefts es, rights es)
60+ **/
17 function partition(es) {
61 function partition(es) {
18 var lrs = Elm.List.partition(isLeft)(es);
62 var lrs = Elm.List.partition(isLeft)(es);
19 lrs[1] = get(lrs[1]);
63 lrs[1] = get(lrs[1]);
core-js/Maybe.js+32
@@ -1,3 +1,35 @@
1+/*! Maybe
2+!*/
3+
4+/*[Definition]*/
5+
6+/** data Maybe a = Just a | Nothing
7+ The Maybe datatype. Useful when a computation may or may not
8+ result in a value (e.g. logarithm is defined only for positive numbers).
9+**/
10+
11+/*[Basic Utilities]*/
12+
13+/** maybe : b -> (a -> b) -> Maybe a -> b
14+ Apply a function to the contents of a `Maybe`.
15+ Return default when given `Nothing`.
16+**/
17+/** isJust : Maybe a -> Bool
18+ Check if constructed with `Just`.
19+**/
20+/** isNothing : Maybe a -> Bool
21+ Check if constructed with `Nothing`.
22+**/
23+
24+/*[Maybe with Lists]*/
25+
26+/** cons : Maybe a -> [a] -> [a]
27+ If `Just`, adds the value to the front of the list.
28+ If `Nothing`, list is unchanged.
29+**/
30+/** justs : [Maybe a] -> [a]
31+ Filters out Nothings and extracts the remaining values.
32+**/
1
33
2Elm.Maybe = function() {
34Elm.Maybe = function() {
3 function consMaybe(x) { return function(xs) {
35 function consMaybe(x) { return function(xs) {
core-js/Signal/HTTP.js+5−5
@@ -11,18 +11,18 @@ Elm.HTTP = function() {
11
11
12 /*[Creating Requests]*/
12 /*[Creating Requests]*/
13
13
14− /** get :: String -> Request String
14+ /** get : String -> Request String
15 Create a GET request to the given url.
15 Create a GET request to the given url.
16 **/
16 **/
17 function get(url) { return request("GET")(url)(null)(["Nil"]); }
17 function get(url) { return request("GET")(url)(null)(["Nil"]); }
18
18
19− /** post :: String -> String -> Request String
19+ /** post : String -> String -> Request String
20 Create a POST request to the given url, carrying the given data.
20 Create a POST request to the given url, carrying the given data.
21 **/
21 **/
22 function post(url) { return function(data) {
22 function post(url) { return function(data) {
23 return request("POST")(url)(data)(["Nil"]); }; }
23 return request("POST")(url)(data)(["Nil"]); }; }
24
24
25− /** request :: String -> String -> String -> [(String,String)] -> Request String
25+ /** request : String -> String -> String -> [(String,String)] -> Request String
26 Create a customized request. Arguments are request type (get, post, put,
26 Create a customized request. Arguments are request type (get, post, put,
27 delete, etc.), target url, data, and a list of additional headers.
27 delete, etc.), target url, data, and a list of additional headers.
28 **/
28 **/
@@ -86,7 +86,7 @@ Elm.HTTP = function() {
86
86
87 /*[Sending Requests]*/
87 /*[Sending Requests]*/
88
88
89− /** send :: Signal (Request a) -> Signal (Response String)
89+ /** send : Signal (Request a) -> Signal (Response String)
90 Performs an HTTP request with the given requests. Produces a signal
90 Performs an HTTP request with the given requests. Produces a signal
91 that carries the responses.
91 that carries the responses.
92 **/
92 **/
@@ -97,7 +97,7 @@ Elm.HTTP = function() {
97 return Elm.Signal.lift2(f)(responses)(sender);
97 return Elm.Signal.lift2(f)(responses)(sender);
98 }
98 }
99
99
100− /** sendGet :: Signal String -> Signal (Response String)
100+ /** sendGet : Signal String -> Signal (Response String)
101 Performs an HTTP GET request with the given urls. Produces a signal
101 Performs an HTTP GET request with the given urls. Produces a signal
102 that carries the responses.
102 that carries the responses.
103 **/
103 **/
core-js/Signal/Keyboard.js+35
@@ -43,6 +43,12 @@ Elm.Keyboard = { Raw : function() {
43 }()
43 }()
44};
44};
45
45
46+/*! Keyboard
47+These are nicely curated inputs from the keyboard. See the
48+[Keyboard.Raw library](/docs/Signal/KeyboardRaw.elm) for a
49+lower-level interface that will let you define more complicated behavior.
50+!*/
51+
46(function() {
52(function() {
47 function keySignal(f) {
53 function keySignal(f) {
48 var signal = Elm.Signal.lift(f)(Elm.Keyboard.Raw.keysDown);
54 var signal = Elm.Signal.lift(f)(Elm.Keyboard.Raw.keysDown);
@@ -79,10 +85,39 @@ Elm.Keyboard = { Raw : function() {
79 return keySignal(f);
85 return keySignal(f);
80 }
86 }
81
87
88+ /*[Directions]*/
89+
90+ /** arrows : Signal { x:Int, y:Int }
91+ A signal of records indicating which arrow keys are pressed.
92+
93+ `{ x = 0, y = 0 }` when pressing no arrows.
94+ `{ x =-1, y = 0 }` when pressing the left arrow.
95+ `{ x = 1, y = 1 }` when pressing the up and right arrows.
96+ `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
97+ **/
82 Elm.Keyboard.arrows = dir(37,39,38,40);
98 Elm.Keyboard.arrows = dir(37,39,38,40);
99+
100+ /** wasd : Signal { x:Int, y:Int }
101+ Just like the arrows signal, but this uses keys w, a, s, and d,
102+ which are common controls for many computer games.
103+ **/
83 Elm.Keyboard.wasd = dir(65,68,87,83);
104 Elm.Keyboard.wasd = dir(65,68,87,83);
105+
106+ /*[Modifiers]*/
107+
108+ /** shift : Signal Bool
109+ Whether the shift key is pressed.
110+ **/
84 Elm.Keyboard.shift = is(16);
111 Elm.Keyboard.shift = is(16);
112+
113+ /** ctrl : Signal Bool
114+ Whether the control key is pressed.
115+ **/
85 Elm.Keyboard.ctrl = is(17);
116 Elm.Keyboard.ctrl = is(17);
117+
118+ /** space : Signal Bool
119+ Whether the space key is pressed.
120+ **/
86 Elm.Keyboard.space = is(32);
121 Elm.Keyboard.space = is(32);
87
122
88}());
123}());
core-js/Signal/Mouse.js+36
@@ -1,15 +1,44 @@
1+/*! Mouse
2+ !*/
1
3
2Elm.Mouse = function() {
4Elm.Mouse = function() {
5+ /*[Position]*/
6+
7+ /** position : Signal (Int,Int)
8+ The current mouse position.
9+ **/
3 var position = Elm.Signal.constant(Value.Tuple(0,0));
10 var position = Elm.Signal.constant(Value.Tuple(0,0));
4 position.defaultNumberOfKids = 2;
11 position.defaultNumberOfKids = 2;
5
12
13+ /** x : Signal Int
14+ The current x-coordinate of the mouse.
15+ **/
6 var x = Elm.Signal.lift(function(p){return p[1];})(position);
16 var x = Elm.Signal.lift(function(p){return p[1];})(position);
7 x.defaultNumberOfKids = 0;
17 x.defaultNumberOfKids = 0;
18+
19+ /** y : Signal Int
20+ The current y-coordinate of the mouse.
21+ **/
8 var y = Elm.Signal.lift(function(p){return p[2];})(position);
22 var y = Elm.Signal.lift(function(p){return p[2];})(position);
9 y.defaultNumberOfKids = 0;
23 y.defaultNumberOfKids = 0;
10
24
25+ /*[Button Status]*/
26+
27+ /** isDown : Signal Bool
28+ The current state of the left mouse-button.
29+ True when the button is down, and false otherwise.
30+ **/
11 var isDown = Elm.Signal.constant(false);
31 var isDown = Elm.Signal.constant(false);
32+
33+ /** isClicked : Signal Bool
34+ True immediately after the left mouse-button has been clicked,
35+ and false otherwise.
36+ **/
12 var isClicked = Elm.Signal.constant(false);
37 var isClicked = Elm.Signal.constant(false);
38+
39+ /** clicks : Signal ()
40+ Always equal to unit. Event triggers on every mouse click.
41+ **/
13 var clicks = Elm.Signal.constant(Value.Tuple());
42 var clicks = Elm.Signal.constant(Value.Tuple());
14
43
15 function getXY(e) {
44 function getXY(e) {
@@ -50,6 +79,13 @@ Elm.Mouse = function() {
50 if (!hasListener)
79 if (!hasListener)
51 this.removeEventListener('mousemove',arguments.callee,false);
80 this.removeEventListener('mousemove',arguments.callee,false);
52 });
81 });
82+
83+ /** isClickedOn : Element -> (Element, Signal Bool)
84+ Determine whether an element has been clicked. The resulting pair
85+ is a signal of booleans that is true when its paired element has
86+ been clicked. The signal is True immediately after the left
87+ mouse-button has been clicked, and false otherwise.
88+ **/
53 var clickedOn = function(elem) {
89 var clickedOn = function(elem) {
54 var node = Render.render(elem);
90 var node = Render.render(elem);
55 var click = Elm.Signal.constant(false);
91 var click = Elm.Signal.constant(false);
core-js/Signal/Random.js+15
@@ -1,9 +1,24 @@
1+/*! Random
2+ !*/
1
3
2Elm.Random = function() {
4Elm.Random = function() {
5+ /*[In a Range]*/
6+
7+ /** inRange : Int -> Int -> Signal Int
8+ Given a range from low to high, this produces a random number
9+ between 'low' and 'high' inclusive. The value in the signal does
10+ not change after the page has loaded.
11+ **/
3 var inRange = function(min) { return function(max) {
12 var inRange = function(min) { return function(max) {
4 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
13 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
5 };
14 };
6 };
15 };
16+
17+ /** randomize : Int -> Int -> Signal a -> Signal Int
18+ Given a range from low to high and a signal of values, this produces
19+ a new signal that changes whenever the input signal changes. The new
20+ values are random number between 'low' and 'high' inclusive.
21+ **/
7 var randomize = function(min) { return function(max) { return function(signal) {
22 var randomize = function(min) { return function(max) { return function(signal) {
8 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
23 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
9 return Elm.Signal.lift(f)(signal);
24 return Elm.Signal.lift(f)(signal);
core-js/Signal/Time.js+4−4
@@ -7,7 +7,7 @@ Elm.Time = function() {
7
7
8 /*[Times]*/
8 /*[Times]*/
9
9
10− /** hour, minute, second, ms :: Time
10+ /** hour, minute, second, ms : Time
11 Units of time, making it easier to specify things like a
11 Units of time, making it easier to specify things like a
12 half-second `(second / 2)`.
12 half-second `(second / 2)`.
13 **/
13 **/
@@ -16,14 +16,14 @@ Elm.Time = function() {
16
16
17 /*[Tickers]*/
17 /*[Tickers]*/
18
18
19− /** fps :: Number -> Signal Time
19+ /** fps : Number -> Signal Time
20 Takes desired number of frames per second (fps). The resulting signal
20 Takes desired number of frames per second (fps). The resulting signal
21 gives a sequence of time deltas as quickly as possible until it reaches
21 gives a sequence of time deltas as quickly as possible until it reaches
22 the desired FPS. A time delta is the time between the last frame and the
22 the desired FPS. A time delta is the time between the last frame and the
23 current frame.
23 current frame.
24 **/
24 **/
25
25
26− /** fpsWhen :: Number -> Signal Bool -> Signal Time
26+ /** fpsWhen : Number -> Signal Bool -> Signal Time
27 Same as the fps function, but you can turn it on and off. Allows you
27 Same as the fps function, but you can turn it on and off. Allows you
28 to do brief animations based on user input without major ineffeciencies.
28 to do brief animations based on user input without major ineffeciencies.
29 The first time delta after a pause is always zero, no matter how long
29 The first time delta after a pause is always zero, no matter how long
@@ -56,7 +56,7 @@ Elm.Time = function() {
56 };
56 };
57 }
57 }
58
58
59− /** every :: Time -> Signal Time
59+ /** every : Time -> Signal Time
60 Takes a time interval t. The resulting signal is the current time,
60 Takes a time interval t. The resulting signal is the current time,
61 updated every t.
61 updated every t.
62 **/
62 **/
core-js/Signal/Touch.js+2−2
@@ -79,7 +79,7 @@ Elm.Touch = function() {
79
79
80 /*[Touches]*/
80 /*[Touches]*/
81
81
82− /** touches :: Signal [{ x :: Int, y :: Int, id :: Int, x0 :: Int, y0 :: Int, t0 :: Time }]
82+ /** touches : Signal [{ x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }]
83 A list of touches. Each ongoing touch is represented by a set of
83 A list of touches. Each ongoing touch is represented by a set of
84 coordinates and an identifier id that allows you to distinguish
84 coordinates and an identifier id that allows you to distinguish
85 between different touches. Each touch also contains the coordinates and
85 between different touches. Each touch also contains the coordinates and
@@ -92,7 +92,7 @@ Elm.Touch = function() {
92
92
93 /*[Gestures]*/
93 /*[Gestures]*/
94
94
95− /** taps :: Signal { x :: Int, y :: Int }
95+ /** taps : Signal { x:Int, y:Int }
96 The last position that was tapped. Default value is `{x=0,y=0}`.
96 The last position that was tapped. Default value is `{x=0,y=0}`.
97 Updates whenever the user taps the screen.
97 Updates whenever the user taps the screen.
98 **/
98 **/
core-js/Signal/WebSocket.js+6−1
@@ -1,7 +1,12 @@
1+/*! WebSocket
2+A library for low latency HTTP communication. See the HTTP library for standard
3+requests like GET, POST, etc.
4+!*/
5+
1Elm.WebSocket = function() {
6Elm.WebSocket = function() {
2 var JS = Elm.JavaScript;
7 var JS = Elm.JavaScript;
3
8
4− /** open :: String -> Signal String -> Signal String
9+ /** open : String -> Signal String -> Signal String
5 Create a web-socket. The first argument is the URL of the desired
10 Create a web-socket. The first argument is the URL of the desired
6 web-socket server. The input signal holds the outgoing messages,
11 web-socket server. The input signal holds the outgoing messages,
7 and the resulting signal contains the incoming ones.
12 and the resulting signal contains the incoming ones.
core-js/Signal/Window.js+3−3
@@ -4,7 +4,7 @@ Elm.Window = function() {
4
4
5 /*[Dimensions]*/
5 /*[Dimensions]*/
6
6
7− /** dimensions :: Signal (Int,Int)
7+ /** dimensions : Signal (Int,Int)
8 The current dimensions of the window (i.e. the area viewable to the
8 The current dimensions of the window (i.e. the area viewable to the
9 user, not including scroll bars).
9 user, not including scroll bars).
10 **/
10 **/
@@ -12,13 +12,13 @@ Elm.Window = function() {
12 window.innerHeight));
12 window.innerHeight));
13 dimensions.defaultNumberOfKids = 2;
13 dimensions.defaultNumberOfKids = 2;
14
14
15− /** width :: Signal Int
15+ /** width : Signal Int
16 The current width of the window.
16 The current width of the window.
17 **/
17 **/
18 var width = Elm.Signal.lift(function(p){return p[1];})(dimensions);
18 var width = Elm.Signal.lift(function(p){return p[1];})(dimensions);
19 width.defaultNumberOfKids = 0;
19 width.defaultNumberOfKids = 0;
20
20
21− /** height :: Signal Int
21+ /** height : Signal Int
22 The current height of the window.
22 The current height of the window.
23 **/
23 **/
24 var height = Elm.Signal.lift(function(p){return p[2];})(dimensions);
24 var height = Elm.Signal.lift(function(p){return p[2];})(dimensions);