on master help sign in
Docs update: copy documentation from elm-lang.org

- Copy documentation from elm-lang.org (dev branch) to .elm files in libraries folder - Added TODO's for stuff that was not found in 0.8 version - Added Review TODO in json.elm

commit441d09c4a76a6d4da3948d47b64aeada9f4e530c authorMads Flensted-Urech <mfu@coadu.com> dateSun 24 Mar 2013, 13:45 (14 years ago) parent893e469
15 files changed+371−28
libraries/Automaton.elm+16−2 libraries/Date.elm+32−1 libraries/Dict.elm+19−1 libraries/Either.elm+14−4 libraries/Graphics/Color.elm+17 libraries/Graphics/Text.elm+46−10 libraries/JavaScript.elm+22 libraries/Json.elm+17−1 libraries/Keyboard.elm−1 libraries/List.elm+71−1 libraries/Set.elm+14−1 libraries/Signal.elm+90−1 libraries/Time.elm+13−3 libraries/Touch.elm−1 libraries/WebSocket.elm−1
libraries/Automaton.elm+16−2
@@ -1,16 +1,22 @@
1−
1+-- This library is a way to package up dynamic behavior. It makes it easier to
2+-- dynamically create dynamic components. See the [original release
3+-- notes](/blog/announce/version-0.5.0.elm) on this library to get a feel for how
4+-- it can be used.
25module Automaton where
36
47data Automaton a b = Automaton (a -> (b, Automaton a b))
58
9+-- Run an automaton on a given signal. The automaton takes in &lsquo;a&rsquo; values and returns &lsquo;b&rsquo; values. The automaton steps forward whenever the input signal updates.
610run : Automaton a b -> Signal a -> Signal b
711run (Automaton m0) input =
812 lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
913
14+-- Step an automaton forward once with a given input.
1015step : Automaton a b -> a -> (b, Automaton a b)
1116step (Automaton m) a = m a
1217
1318
19+-- Compose two automatons, chaining them together.
1420(>>>) : Automaton a b -> Automaton b c -> Automaton a c
1521a1 >>> a2 =
1622 let Automaton m1 = a1
@@ -19,23 +25,29 @@ a1 >>> a2 =
1925 (c,m2') = m2 b
2026 in (c, m1' >>> m2'))
2127
28+-- Compose two automatons, chaining them together.
2229(<<<) : Automaton b c -> Automaton a b -> Automaton a c
2330a2 <<< a1 = a1 >>> a2
2431
32+-- Combine a list of automatons into a single automaton that produces a list.
2533combine : [Automaton a b] -> Automaton a [b]
2634combine autos =
2735 Automaton (\a -> let (bs,autos') = unzip $ map (\(Automaton m) -> m a) autos in
2836 (bs, combine autos'))
2937
38+-- Create an automaton with no memory. It just applies the given function to every input.
3039pure : (a -> b) -> Automaton a b
3140pure f = Automaton (\x -> (f x, pure f))
3241
42+-- Create an automaton with no memory. It just applies the given function to every input.
3343init : b -> (a -> b -> b) -> Automaton a b
3444init s step = Automaton (\a -> let s' = step a s in (s', init s' step))
3545
46+-- Create an automaton with hidden state. Requires an initial state and a step function to step the state forward and produce an output.
3647init' : s -> (a -> s -> (b,s)) -> Automaton a b
3748init' s step = Automaton (\a -> let (b,s') = step a s in (b , init' s' step))
3849
50+-- Count the number of steps taken.
3951count : Automaton a Int
4052count = init 0 (\_ c -> c + 1)
4153
@@ -56,6 +68,7 @@ stepDrag (press,pos) (ds,form) =
5668 else (let form' = uncurry move (vecSub pos p0) form in
5769 (form', (Listen,form')))
5870
71+-- Create a draggable form that can be dynamically created and added to a scene.
5972draggable : Form -> Automaton (Bool,(Int,Int)) Form
6073draggable form = init' (Listen,form) stepDrag
6174
@@ -68,4 +81,5 @@ draggable form = init' (Listen,form) stepDrag
6881Speeding things up is a really low priority. Language features and
6982libraries with nice APIs and are way more important!
7083
71−--}
84+--}
85+
libraries/Date.elm+32−1
@@ -1,19 +1,50 @@
11
2+-- Library for working with dates. It is still a work in progress, so email
3+-- the mailing list if you are having issues with internationalization or
4+-- locale formatting or something.
25module Date where
36
7+-- Represents the days of the week.
48data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
59
10+-- Represents the month of the year.
611data Month = Jan | Feb | Mar | Apr
712 | May | Jun | Jul | Aug
813 | Sep | Oct | Nov | Dec
914
10−read : String -> Date
15+-- Attempt to read a date from a string.
16+read : String -> Maybe Date
17+
18+-- Convert a date into a time since midnight (UTC) of 1 January 1990 (i.e.
19+-- [UNIX time](http://en.wikipedia.org/wiki/Unix_time)). Given the date 23 June
20+-- 1990 at 11:45AM this returns the corresponding time.
1121toTime : Date -> Time
1222
23+-- Extract the year of a given date. Given the date 23 June 1990 at 11:45AM
24+-- this returns the integer `1990`.
1325year : Date -> Int
26+
27+-- Extract the month of a given date. Given the date 23 June 1990 at 11:45AM
28+-- this returns the Month `Jun` as defined below.
1429month : Date -> Month
30+
31+
32+-- Extract the day of a given date. Given the date 23 June 1990 at 11:45AM
33+-- this returns the integer `23`.
1534day : Date -> Int
35+
36+-- Extract the day of the week for a given date. Given the date 23 June
37+-- 1990 at 11:45AM this returns the Day `Thu` as defined below.
1638dayOfWeek : Date -> Day
39+
40+-- Extract the hour of a given date. Given the date 23 June 1990 at 11:45AM
41+-- this returns the integer `11`.
1742hour : Date -> Int
43+
44+-- Extract the minute of a given date. Given the date 23 June 1990 at 11:45AM
45+-- this returns the integer `45`.
1846minute : Date -> Int
47+
48+-- Extract the second of a given date. Given the date 23 June 1990 at 11:45AM
49+-- this returns the integer `0`.
1950second : Date -> Int
libraries/Dict.elm+19−1
@@ -16,6 +16,7 @@ data NColor = Red | Black
1616
1717data Dict k v = Node NColor k v (Dict k v) (Dict k v) | Empty
1818
19+-- Create an empty dictionary.
1920empty : Dict k v
2021empty = Empty
2122
@@ -114,6 +115,7 @@ max t =
114115 }
115116--}
116117
118+-- Lookup the value associated with a key.
117119lookup : k -> Dict k v -> Maybe v
118120lookup k t =
119121 case t of
@@ -124,6 +126,7 @@ lookup k t =
124126 EQ -> Just v
125127 GT -> lookup k r
126128
129+-- Find the value associated with a key. If the key is not found, return the default value.
127130findWithDefault : v -> k -> Dict k v -> v
128131findWithDefault base k t =
129132 case t of
@@ -135,6 +138,7 @@ findWithDefault base k t =
135138 GT -> findWithDefault base k r
136139
137140{--
141+-- Find the value associated with a key. If the key is not found, there will be a runtime error.
138142find k t =
139143 case t of
140144 { Empty -> Error.raise "Key was not found in dictionary!"
@@ -146,8 +150,9 @@ find k t =
146150 }
147151--}
148152
149−-- Does t contain k?
153+-- Determine if a key is in a dictionary.
150154member : k -> Dict k v -> Bool
155+-- Does t contain k?
151156member k t = Maybe.isJust $ lookup k t
152157
153158rotateLeft : Dict k v -> Dict k v
@@ -201,6 +206,7 @@ ensureBlackRoot t =
201206 Node Red k v l r -> Node Black k v l r
202207 _ -> t
203208
209+-- Insert a key-value pair into a dictionary. Replaces value when there is a collision.
204210-- Invariant: t is a valid left-leaning rb tree *)
205211insert : k -> v -> Dict k v -> Dict k v
206212insert k v t =
@@ -223,6 +229,7 @@ insert k v t =
223229 else new_t)
224230--}
225231
232+-- Create a dictionary with one key-value pair.
226233singleton : k -> v -> Dict k v
227234singleton k v = insert k v Empty
228235
@@ -303,6 +310,7 @@ deleteMax t =
303310 in ensureBlackRoot (del t)
304311--}
305312
313+-- Remove a key-value pair from a dictionary. If the key is not found, no changes are made.
306314remove : k -> Dict k v -> Dict k v
307315remove k t =
308316 let eq_and_noRightNode t =
@@ -335,43 +343,53 @@ remove k t =
335343 Error.raise "invariants broken after remove")
336344--}
337345
346+-- Apply a function to all values in a dictionary.
338347map : (a -> b) -> Dict k a -> Dict k b
339348map f t =
340349 case t of
341350 Empty -> Empty
342351 Node c k v l r -> Node c k (f v) (map f l) (map f r)
343352
353+-- Fold over the key-value pairs in a dictionary, in order from lowest key to highest key.
344354foldl : (k -> v -> b -> b) -> b -> Dict k v -> b
345355foldl f acc t =
346356 case t of
347357 Empty -> acc
348358 Node _ k v l r -> foldl f (f k v (foldl f acc l)) r
349359
360+-- Fold over the key-value pairs in a dictionary, in order from highest key to lowest key.
350361foldr : (k -> v -> b -> b) -> b -> Dict k v -> b
351362foldr f acc t =
352363 case t of
353364 Empty -> acc
354365 Node _ k v l r -> foldr f (f k v (foldr f acc r)) l
355366
367+-- Combine two dictionaries. If there is a collision, preference is given to the first dictionary.
356368union : Dict k v -> Dict k v -> Dict k v
357369union t1 t2 = foldl insert t2 t1
358370
371+-- Keep a key-value pair when its key appears in the second dictionary. Preference is given to values in the first dictionary.
359372intersect : Dict k v -> Dict k v -> Dict k v
360373intersect t1 t2 =
361374 let combine k v t = if k `member` t2 then insert k v t else t
362375 in foldl combine empty t1
363376
377+-- Keep a key-value pair when its key does not appear in the second dictionary. Preference is given to the first dictionary.
364378diff : Dict k v -> Dict k v -> Dict k v
365379diff t1 t2 = foldl (\k v t -> remove k t) t1 t2
366380
381+-- Get all of the keys in a dictionary.
367382keys : Dict k v -> [k]
368383keys t = foldr (\k v acc -> k :: acc) [] t
369384
385+-- Get all of the values in a dictionary.
370386values : Dict k v -> [v]
371387values t = foldr (\k v acc -> v :: acc) [] t
372388
389+-- Convert a dictionary into an association list of key-value pairs.
373390toList : Dict k v -> [(k,v)]
374391toList t = foldr (\k v acc -> (k,v) :: acc) [] t
375392
393+-- Convert an association list into a dictionary.
376394fromList : [(k,v)] -> Dict k v
377395fromList assocs = List.foldl (uncurry insert) empty assocs
libraries/Either.elm+14−4
@@ -3,24 +3,34 @@ module Either where
33
44import List
55
6+-- Represents any data that can take two different types.
7+--
8+-- This can also be used for error handling `(Either String a)` where error
9+-- messages are stored on the left, and the correct values (&ldquo;right&rdquo; values) are stored on the right.
610data Either a b = Left a | Right b
711
12+-- Apply the first function to a `Left` and the second function to a `Right`.
13+-- This allows the extraction of a value from an `Either`.
814either : (a -> c) -> (b -> c) -> Either a b -> c
915either f g e = case e of { Left x -> f x ; Right y -> g y }
1016
11−
17+-- True if the value is a `Left`.
1218isLeft : Either a b -> Bool
1319isLeft e = case e of { Left _ -> True ; _ -> False }
1420
21+-- True if the value is a `Right`.
1522isRight : Either a b -> Bool
1623isRight e = case e of { Right _ -> True ; _ -> False }
1724
18−
25+-- Keep only the values held in `Left` values.
1926--lefts : [Either a b] -> [a]
2027lefts es = List.filter isLeft es
2128
29+-- Keep only the values held in `Right` values.
2230--rights : [Either a b] -> [b]
2331rights es = List.filter isRight es
2432
25−--partition : [Either a b] -> ([a],[b])
26−partition es = List.partition isLeft es
33+-- Split into two lists, lefts on the left and rights on the right. So we
34+-- have the equivalence: `(partition es == (lefts es, rights es))`
35+-- partition : [Either a b] -> ([a],[b])
36+partition es = List.partition isLeft es
libraries/Graphics/Color.elm+17
@@ -11,7 +11,10 @@ module Graphics.Color (rgba,rgb,hsva,hsv,
1111
1212data Color = Color Int Int Int Float
1313
14+-- Create RGB colors with an alpha component for transparency. The alpha component is specified with numbers between 0 and 1.
1415rgba = Color
16+
17+-- Create RGB colors from numbers between 0 and 255 inclusive.
1518rgb r g b = Color r g b 1
1619
1720red = Color 255 0 0 1
@@ -38,8 +41,22 @@ purple = Color 128 0 128 1
3841forestGreen = Color 34 139 34 1
3942violet = Color 238 130 238 1
4043
44+-- Produce a &ldquo;complementary color&rdquo;. The two colors will accent each other.
4145complement : Color -> Color
46+
47+-- Create HSV colors with an alpha component for transparency. The alpha component is specified with numbers between 0 and 1.
4248hsva : Int -> Float -> Float -> Float -> Color
49+
50+-- Create HSV colors. HSV stands for hue-saturation-value.
51+--
52+-- Hue is a degree from 0 to 360 representing a color wheel: red at 0&deg;, green at 120&deg;, blue at 240&deg;, and red again at 360&deg;.
53+-- This makes it easy to cycle through colors and compute color complements, triads, tetrads, etc.
54+--
55+-- Saturation is a number between 1 and 0 where lowering this number makes your color more grey. This can help you tone a color down.
56+--
57+-- Value is also a number between 1 and 0. Lowering this number makes your color more black.
58+--
59+-- Look up the &ldquo;HSV cylinder&rdquo; for more information.
4360hsv : Int -> Float -> Float -> Color
4461
4562data Gradient
libraries/Graphics/Text.elm+46−10
@@ -4,21 +4,57 @@ module Graphics.Text where
44import Native.Graphics.Text as T
55
66
7+-- Convert a string into text which can be styled and displayed.
78toText : String -> Text
89
9−typeface : String -> Text -> Text
10−href : String -> Text -> Text
11−height : Float -> Text -> Text
12−color : Color -> Text -> Text
13−bold : Text -> Text
14−italic : Text -> Text
15−overline : Text -> Text
10+-- Set the typeface of some text. The first argument should be a comma separated listing of the desired typefaces
11+-- "helvetica, arial, sans-serif"
12+-- Works the same as the CSS font-family property.
13+typeface : String -> Text -> Text
14+
15+-- Switch to a monospace typeface. Good for code snippets.
16+monospace : Text -> Text
17+
18+-- Make text big and noticable.
19+header : Text -> Text
20+
21+-- Create a link.
22+href : String -> Text -> Text
23+
24+-- Set the height of text in \"ems\". 1em is the normal height of text. 2ems is twice that height.
25+height : Float -> Text -> Text
26+
27+-- Set the color of a string.
28+color : Color -> Text -> Text
29+
30+-- Make a string bold.
31+bold : Text -> Text
32+
33+-- Italicize a string.
34+italic : Text -> Text
35+
36+-- Draw a line above a string.
37+overline : Text -> Text
38+
39+-- Underline a string.
1640underline : Text -> Text
41+
42+-- Draw a line through a string.
1743strikeThrough : Text -> Text
1844
45+-- Display justified, styled text.
1946justified : Text -> Element
20−centered : Text -> Element
21−righted : Text -> Element
22−text : Text -> Element
2347
48+-- Display centered, styled text.
49+centered : Text -> Element
50+
51+-- Display right justified, styled text.
52+righted : Text -> Element
53+
54+-- Display styled text.
55+text : Text -> Element
56+
57+-- Convert anything to it's textual representation and make it displayable in browser
58+-- asText = text . monospace . show
59+-- Excellent for debugging
2460asText : a -> Element
libraries/JavaScript.elm+22
@@ -5,17 +5,39 @@ module JavaScript where
55-- To Elm
66
77toString : JSString -> String
8+
9+-- Requires that the input array be uniform (all members have the same type)
810toList : JSArray a -> [a]
11+
912toInt : JSNumber -> Int
1013toFloat : JSNumber -> Float
14+
15+-- Conversion from JavaScript boolean values to Elm boolean values.
1116toBool : JSBool -> Bool
1217
1318
1419-- From Elm
1520
1621fromString : String -> JSString
22+
23+-- Produces a uniform JavaScript array with all members of the same type.
1724fromList : [a] -> JSArray a
25+
1826fromInt : Int -> JSNumber
1927fromFloat : Float -> JSNumber
28+
29+-- Conversion from Elm boolean values to JavaScript boolean values.
2030fromBool : Bool -> JSBool
2131
32+{-- TODO: only found in docs
33+
34+ , ("castTupleToJSTuple2" , "(a,b) -> JSTuple2 a b", "A JSTupleN is an array of size N with nonuniform types. Each member can have a different type.")
35+ , ("castJSTupleToTuple2" , "JSTuple2 a b -> (a,b)", "")
36+ , ("castTupleToJSTuple3" , "(a,b,c) -> JSTuple3 a b c", "")
37+ , ("castJSTupleToTuple3" , "JSTuple3 a b c > (a,b,c)", "")
38+ , ("castTupleToJSTuple4" , "(a,b,c,d) -> JSTuple4 a b c d", "")
39+ , ("castJSTupleToTuple4" , "JSTuple4 a b c d -> (a,b,c,d)", "")
40+ , ("castTupleToJSTuple5" , "(a,b,c,d,e) -> JSTuple5 a b c d e", "")
41+ , ("castJSTupleToTuple5" , "JSTuple5 a b c d e -> (a,b,c,d,e)", "")
42+
43+--}
libraries/Json.elm+17−1
@@ -1,11 +1,14 @@
11
2+-- TOOD: Evan please review texts
3+
24module Json where
35
46import Dict as Dict
57import JavaScript as JS
68import Native.Json as Native
79
8−
10+-- This datatype can represent all valid values that can be held in a JSON object.
11+-- In Elm, a proper JSON object is represented as a (Dict String Value) which is a mapping from strings to Json Values.
912data Value
1013 = String String
1114 | Number Float
@@ -17,18 +20,25 @@ data Value
1720
1821-- String Converters
1922
23+-- Convert a proper JSON object into a string.
2024toString : Value -> String
2125toString v = JS.toString (Native.toPrettyJSString "" v)
2226
27+-- Convert a proper JSON object into a prettified string.
28+-- The first argument is a separator token (e.g. \" \", \"\\n\", etc.) that will be used for indentation in the prettified string version of the JSON object.
2329toPrettyString : String -> Value -> String
2430toPrettyString sep v = JS.toString (Native.toPrettyJSString sep v)
2531
32+-- Convert a proper JSON object into a JavaScript string.
33+-- Note that the type JSString seen here is not the same as the type constructor JsonString used elsewhere in this module.
2634toJSString : Value -> JSString
2735toJSString v = Native.toPrettyJSString "" v
2836
37+-- Parse a string representation of a proper JSON object into its Elm's representation.
2938fromString : String -> Maybe Value
3039fromString s = Native.fromJSString (JS.fromString s)
3140
41+-- Parse a JavaScript string representation of a proper JSON object into its Elm's representation.
3242fromJSString : JSString -> Maybe Value
3343
3444
@@ -52,6 +62,7 @@ object v = case v of { Object o -> o ; _ -> Dict.empty }
5262
5363-- Extract Elm values from dictionaries of Json values
5464
65+-- Find a value in a Json Object using the passed get function. If the key is not found, this returns the given default/base value.
5566find get base =
5667 let f key dict =
5768 case Dict.lookup key dict of
@@ -59,17 +70,22 @@ find get base =
5970 Just v -> get v
6071 in f
6172
73+-- Find a string value in an Elm Json object. If the key is not found or the value found is not a string, this returns the empty string.
6274findString : String -> Dict String Value -> String
6375findString = find string ""
6476
77+-- Find a number value in an Elm Json object. If the key is not found or the value found is not a number, this returns 0
6578findNumber : String -> Dict String Value -> Float
6679findNumber = find number 0
6780
81+-- Find a boolean value in an Elm Json object. If the key is not found or the value found is not a boolean, this returns the False.
6882findBoolean : String -> Dict String Value -> Bool
6983findBoolean = find boolean False
7084
85+-- Find an array value in an Elm Json object. If the key is not found or the value found is not an array, this returns an empty list.
7186findArray : String -> Dict String Value -> [Value]
7287findArray = find array []
7388
89+-- Find an object value in an Elm Json object. If the key is not found or the value found is not an object, this returns an empty object.
7490findObject : String -> Dict String Value -> Dict String Value
7591findObject = find object Dict.empty
libraries/Keyboard.elm−1
@@ -1,7 +1,6 @@
11-- These are nicely curated inputs from the keyboard. See the
22-- [Keyboard.Raw library](/docs/Signal/KeyboardRaw.elm) for a
33-- lower-level interface that will let you define more complicated behavior.
4−
54module Keyboard where
65
76import Native.Keyboard as N
libraries/List.elm+71−1
@@ -4,36 +4,77 @@ module List where
44import Native.Utils (min, max)
55import Native.List as L
66
7+-- Extract the first element of a list. List must be non-empty.
78head : [a] -> a
9+
10+-- Extract the elements after the head of the list. List must be non-empty.
811tail : [a] -> [a]
12+
13+-- Extract the last element of a list. List must be non-empty.
914last : [a] -> a
15+
16+-- Apply a function to every element of a list.
1017map : (a -> b) -> [a] -> [b]
18+
19+-- Reduce a list from the left.
1120foldl : (a -> b -> b) -> b -> [a] -> b
21+
22+-- Reduce a list from the right.
1223foldr : (a -> b -> b) -> b -> [a] -> b
24+
25+-- Reduce a list from the left without a base case. List must be non-empty.
1326foldl1 : (a -> a -> a) -> [a] -> a
27+
28+-- Reduce a list from the right without a base case. List must be non-empty.
1429foldr1 : (a -> a -> a) -> [a] -> a
1530
31+-- Reduce a list from the left, building up all of the intermediate results into a list.
1632scanl : (a -> b -> b) -> b -> [a] -> [b]
33+
34+-- Same as scanl but it doesn't require a base case. List must be non-empty.
1735scanl1 : (a -> a -> a) -> [a] -> [a]
1836
37+-- Filter out elements which do not satisfy the predicate.
1938filter : (a -> Bool) -> [a] -> [a]
39+
40+-- Determine the length of a list.
2041length : [a] -> Int
42+
43+-- Reverse a list.
2144reverse : [a] -> [a]
2245
46+-- Check to see if all elements satisfy the predicate.
2347all : (a -> Bool) -> [a] -> Bool
48+
49+-- Check to see if any elements satisfy the predicate.
2450any : (a -> Bool) -> [a] -> Bool
51+
52+-- Check to see if all elements are True.
2553and : [Bool] -> Bool
54+
55+-- Check to see if any elements are True.
2656or : [Bool] -> Bool
2757
58+-- Flatten a list of lists.
2859concat : [[a]] -> [a]
60+
61+-- Map a given function onto a list and flatten the resulting lists. (concatMap f xs == concat (map f xs))
2962concatMap : (a -> [b]) -> [a] -> [b]
3063concatMap f = L.concat . L.map f
3164
65+-- Get the sum of the list elements.
3266sum = L.foldl (+) 0
67+
68+-- Get the product of the list elements.
3369product = L.foldl (*) 1
70+
71+-- Find the highest number in a non-empty list.
3472maximum = L.foldl1 max
73+
74+-- Find the lowest number in a non-empty list.
3575minimum = L.foldl1 min
3676
77+-- Split a list based on the predicate.
3778partition : (a -> Bool) -> [a] -> ([a],[a])
3879partition pred lst =
3980 case lst of
@@ -41,18 +82,28 @@ partition pred lst =
4182 x::xs -> let (bs,cs) = partition pred xs in
4283 if pred x then (x::bs,cs) else (bs,x::cs)
4384
44−zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
85+-- Combine two lists, combining them into tuples pairwise. If one input list has extra elements (it is longer), those elements are dropped.
4586zip : [a] -> [b] -> [(a,b)]
4687
88+-- Combine two lists, combining them with the given function. If one input list has extra elements (it is longer), those elements are dropped.
89+zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
90+
91+-- Decompose a list of tuples
4792unzip : [(a,b)] -> ([a],[b])
4893unzip pairs =
4994 case pairs of
5095 [] -> ([],[])
5196 (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
5297
98+-- Split a list
99+-- split "," "hello,there,friend" == ["hello", "there", "friend"]
53100split : [a] -> [a] -> [[a]]
101+
102+-- Places the given value between all of the lists in the second argument and concatenates the result.
103+-- join xs xss = concat (intersperse xs xss)
54104join : [a] -> [[a]] -> [a]
55105
106+-- Places the given value between all members of the given list.
56107intersperse : a -> [a] -> [a]
57108intersperse sep xs =
58109 case xs of
@@ -60,3 +111,22 @@ intersperse sep xs =
60111 [a] -> [a]
61112 [] -> []
62113
114+{-- TODO: only found in docs
115+
116+-- Add an element to the front of a list
117+-- a :: [b,c] = [a,b,c]
118+(::) : a -> [a] -> [a]
119+
120+-- Appends two lists.
121+(++) : [a] -> [a] -> [a]
122+
123+-- Take the first n members of a list.
124+-- take 2 [1,2,3,4]) ==> [1,2]
125+take : Int -> [a] -> [a]
126+
127+-- Drop the first n members of a list.
128+-- drop 2 [1,2,3,4]) ==> [3,4]
129+drop : Int -> [a] -> [a]
130+
131+--}
132+
libraries/Set.elm+14−1
@@ -11,41 +11,54 @@ import List as List
1111
1212type Set t = Dict t ()
1313
14+-- Create an empty set.
1415empty : Set t
1516empty = Dict.empty
1617
18+-- Create a set with one value.
1719singleton : t -> Set t
1820singleton k = Dict.singleton k ()
1921
22+-- Insert a value into a set.
2023insert : t -> Set t -> Set t
2124insert k = Dict.insert k ()
2225
26+-- Remove a value from a set. If the value is not found, no changes are made.
2327remove : t -> Set t -> Set t
2428remove = Dict.remove
2529
30+-- Determine if a value is in a set.
2631member : t -> Set t -> Bool
2732member = Dict.member
2833
34+-- Get the union of two sets. Keep all values.
2935union : Set t -> Set t -> Set t
3036union = Dict.union
3137
38+-- Get the intersection of two sets. Keeps values that appear in both sets.
3239intersect : Set t -> Set t -> Set t
3340intersect = Dict.intersect
3441
42+-- Get the difference between the first set and the second. Keeps values that do not appear in the second set.
3543diff : Set t -> Set t -> Set t
3644diff = Dict.diff
3745
46+-- Convert a set into a list.
3847toList : Set t -> [t]
3948toList = Dict.keys
4049
50+-- Convert a list into a set, removing any duplicates.
4151fromList : [t] -> Set t
4252fromList xs = List.foldl (\k t -> Dict.insert k () t) empty xs
4353
54+-- Fold over the values in a set, in order from lowest to highest.
4455foldl : (a -> b -> b) -> b -> Set a -> b
4556foldl f b s = Dict.foldl (\k _ b -> f k b) b s
4657
58+-- Fold over the values in a set, in order from highest to lowest.
4759foldr : (a -> b -> b) -> b -> Set a -> b
4860foldr f b s = Dict.foldr (\k _ b -> f k b) b s
4961
62+-- Map a function onto a set, creating a new set with no duplicates.
5063map : (a -> b) -> Set a -> Set b
51−map f s = fromList (List.map f (toList s))
64+map f s = fromList (List.map f (toList s))
libraries/Signal.elm+90−1
@@ -1,12 +1,24 @@
11
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.
6+--
7+-- Note: There are lift functions up to `lift8`.
28module Signal where
39
410import Native.Signal as Native
511
12+-- Create a constant signal that never changes.
613constant : a -> Signal a
714
15+-- Transform a signal with a given function.
816lift : (a -> b) -> Signal a -> Signal b
17+
18+-- Combine two signals with a given function.
919lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
20+
21+-- Combine three signals with a given function.
1022lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
1123lift4 : (a -> b -> c -> d -> e) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e
1224lift5 : (a -> b -> c -> d -> e -> f) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f
@@ -14,21 +26,98 @@ lift6 : (a -> b -> c -> d -> e -> f -> g) -> Signal a -> Signal b -> Signal c ->
1426lift7 : (a -> b -> c -> d -> e -> f -> g -> h) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h
1527lift8 : (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
1628
29+-- Create a past-dependent signal. Each value given on the input signal will
30+-- be accumulated, producing a new output value.
31+--
32+-- For instance, `(foldp (\\t acc -> acc + 1) 0 (Time.every second))` increments every second.
1733foldp : (a -> b -> b) -> b -> Signal a -> Signal b
1834
35+-- Merge two signals into one, biased towards the first signal if both signals
36+-- update at the same time.
1937merge : Signal a -> Signal a -> Signal a
38+
39+-- Merge many signals into one, biased towards the left-most signal if multiple
40+-- signals update simultaneously.
2041merges : [Signal a] -> Signal a
42+
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.
2146mergeEither : Signal a -> Signal b -> Signal (Either a b)
2247
48+-- Count the number of events that have occured.
2349count : Signal a -> Signal Int
50+
51+-- Count the number of events that have occured that satisfy a given predicate.
2452countIf : (a -> Bool) -> Signal a -> Signal Int
2553
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
56+-- never satisfied.
2657keepIf : (a -> Bool) -> a -> Signal a -> Signal a
58+
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
61+-- satisfied.
2762dropIf : (a -> Bool) -> a -> Signal a -> Signal a
63+
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.
2869keepWhen : Signal Bool -> a -> Signal a -> Signal a
70+
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
75+-- always true.
2976dropWhen : Signal Bool -> a -> Signal a -> Signal a
77+
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.
3081dropRepeats : Signal a -> Signal a
3182
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.
3286sampleOn : Signal a -> Signal b -> Signal b
3387
34−timestamp : Signal a -> Signal (Time, a)
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.
91+timestamp : Signal a -> Signal (Time, a)
92+
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.
95+delay : Time -> Signal a -> Signal a
96+
97+{-- TODO: only found in docs
98+ , ("average", "Int -> Signal Number -> Signal Float", [markdown|
99+
100+Takes an integer `n` and a signal of numbers. Computes the running
101+average of the signal over the last `n` events.
102+
103+So `(average 20 (fps 40))` would be the average time between the frames for
104+the 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|])
122+--}
123+
libraries/Time.elm+13−3
@@ -1,6 +1,4 @@
1−-- Library for working with time. Type `Time` represents some number of
2−-- milliseconds.
3−
1+-- Library for working with time. Type `Time` represents some number of milliseconds.
42module Time where
53
64import Native.Time as T
@@ -50,3 +48,15 @@ fpsWhen : Number -> Signal Bool -> Signal Time
5048-- Takes a time interval t. The resulting signal is the current time,
5149-- updated every t.
5250every : Time -> Signal Time
51+
52+-- Takes a time `t` and any signal. The resulting boolean signal
53+-- is true for time `t` after every event on the input signal.
54+-- So ``(second `since` Mouse.clicks)`` would result in a signal
55+-- that is true for one second after each mouse click and false
56+-- otherwise.
57+since : Time -> Signal a -> Signal Bool
58+
59+{-- TODO: Only found in docs
60+ , ("timeOf", "Signal a -> Signal Time", [markdown|
61+ Same as `timestamp` but it throws out the incoming value. So `(timeOf == lift fst . timestamp)`.|])
62+--}
libraries/Touch.elm−1
@@ -1,6 +1,5 @@
11-- This is an early version of the touch library. It will likely grow to
22-- include gestures that would be useful for both games and web-pages.
3−
43module Touch where
54
65import Native.Touch as T
libraries/WebSocket.elm−1
@@ -1,6 +1,5 @@
11-- A library for low latency HTTP communication. See the HTTP library for
22-- standard requests like GET, POST, etc.
3−
43module WebSocket where
54
65import Native.WebSocket as WS