@@ -9,8 +9,8 @@ import Native.List as L
99
1010-- Puts two appendable things together:
1111--
12−-- [1,1] ++ [2,3] == [1,1,2,3]
13−-- "abc" ++ "123" == "abc123"
12+-- [1,1] ++ [2,3] == [1,1,2,3]
13+-- "abc" ++ "123" == "abc123"
1414(++) : Appendable a -> Appendable a -> Appendable a
1515
1616-- Extract the first element of a list. List must be non-empty.
@@ -25,6 +25,13 @@ tail : [a] -> [a]
2525-- `(last [1,2,3] == 3)`
2626last : [a] -> a
2727
28+-- Check if a list is empty `(isEmpty [] == True)`
29+isEmpty : [a] -> Bool
30+isEmpty xs =
31+ case xs of
32+ [] -> True
33+ _ -> False
34+
2835-- Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])`
2936map : (a -> b) -> [a] -> [b]
3037
@@ -42,12 +49,12 @@ foldr1 : (a -> a -> a) -> [a] -> a
4249
4350-- Reduce a list from the left, building up all of the intermediate results into a list.
4451--
45−-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
52+-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
4653scanl : (a -> b -> b) -> b -> [a] -> [b]
4754
4855-- Same as scanl but it doesn't require a base case. List must be non-empty.
4956--
50−-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
57+-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
5158scanl1 : (a -> a -> a) -> [a] -> [a]
5259
5360-- Filter out elements which do not satisfy the predicate: `(filter isLower "AaBbCc" == "abc")`
@@ -73,12 +80,12 @@ or : [Bool] -> Bool
7380
7481-- Concatenate a list of appendable things:
7582--
76−-- concat ["tree","house"] == "treehouse"
83+-- concat ["tree","house"] == "treehouse"
7784concat : [Appendable a] -> Appendable a
7885
7986-- Map a given function onto a list and flatten the resulting lists.
8087--
81−-- concatMap f xs == concat (map f xs)
88+-- concatMap f xs == concat (map f xs)
8289concatMap : (a -> Appendable b) -> [a] -> Appendable b
8390concatMap f = L.concat . L.map f
8491
@@ -109,14 +116,14 @@ partition pred lst =
109116-- Combine two lists, combining them into tuples pairwise.
110117-- If one list is longer, the extra elements are dropped.
111118--
112−-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
113−-- zip == zipWith (,)
119+-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
120+-- zip == zipWith (,)
114121zip : [a] -> [b] -> [(a,b)]
115122
116123-- Combine two lists, combining them with the given function.
117124-- If one list is longer, the extra elements are dropped.
118125--
119−-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
126+-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
120127zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
121128
122129-- Decompose a list of tuples.
@@ -128,18 +135,18 @@ unzip pairs =
128135
129136-- Split a list with a given seperator.
130137--
131−-- split "," "hello,there,friend" == ["hello", "there", "friend"]
138+-- split "," "hello,there,friend" == ["hello", "there", "friend"]
132139split : [a] -> [a] -> [[a]]
133140
134141-- Places the given value between all of the lists in the second argument
135142-- and concatenates the result.
136143--
137−-- join "a" ["H","w","ii","n"] == "Hawaiian"
144+-- join "a" ["H","w","ii","n"] == "Hawaiian"
138145join : Appendable a -> [Appendable a] -> Appendable a
139146
140147-- Places the given value between all members of the given list.
141148--
142−-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
149+-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
143150intersperse : a -> [a] -> [a]
144151intersperse sep xs =
145152 case xs of