4import Native.Utils (min, max)
7-- Add an element to the front of a list `(1 :: [2,3] == [1,2,3])`
10-- Puts two appendable things together:
12-- [1,1] ++ [2,3] == [1,1,2,3]
13-- "abc" ++ "123" == "abc123"
14(++) : Appendable a -> Appendable a -> Appendable a
16-- Extract the first element of a list. List must be non-empty.
17-- `(head [1,2,3] == 1)`
20-- Extract the elements after the head of the list. List must be non-empty.
21-- `(tail [1,2,3] == [2,3])`
24-- Extract the last element of a list. List must be non-empty.
25-- `(last [1,2,3] == 3)`
28-- Check if a list is empty `(isEmpty [] == True)`
35-- Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])`
36map : (a -> b) -> [a] -> [b]
38-- Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")`
39foldl : (a -> b -> b) -> b -> [a] -> b
41-- Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)`
42foldr : (a -> b -> b) -> b -> [a] -> b
44-- Reduce a list from the left without a base case. List must be non-empty.
45foldl1 : (a -> a -> a) -> [a] -> a
47-- Reduce a list from the right without a base case. List must be non-empty.
48foldr1 : (a -> a -> a) -> [a] -> a
50-- Reduce a list from the left, building up all of the intermediate results into a list.
52-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
53scanl : (a -> b -> b) -> b -> [a] -> [b]
55-- Same as scanl but it doesn't require a base case. List must be non-empty.
57-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
58scanl1 : (a -> a -> a) -> [a] -> [a]
60-- Filter out elements which do not satisfy the predicate: `(filter isLower "AaBbCc" == "abc")`
61filter : (a -> Bool) -> [a] -> [a]
63-- Determine the length of a list: `(length "innumerable" == 11)`
66-- Reverse a list. `(reverse [1..4] == [4,3,2,1])`
69-- Check to see if all elements satisfy the predicate.
70all : (a -> Bool) -> [a] -> Bool
72-- Check to see if any elements satisfy the predicate.
73any : (a -> Bool) -> [a] -> Bool
75-- Check to see if all elements are True.
78-- Check to see if any elements are True.
81-- Concatenate a list of appendable things:
83-- concat ["tree","house"] == "treehouse"
84concat : [Appendable a] -> Appendable a
86-- Map a given function onto a list and flatten the resulting lists.
88-- concatMap f xs == concat (map f xs)
89concatMap : (a -> Appendable b) -> [a] -> Appendable b
90concatMap f = L.concat . L.map f
92-- Get the sum of the list elements. `(sum [1..4] == 10)`
93sum : [Number a] -> Number a
96-- Get the product of the list elements. `(product [1..4] == 24)`
97product : [Number a] -> Number a
98product = L.foldl (*) 1
100-- Find the highest number in a non-empty list.
101maximum : [Number a] -> Number a
102maximum = L.foldl1 max
104-- Find the lowest number in a non-empty list.
105minimum : [Number a] -> Number a
106minimum = L.foldl1 min
108-- Split a list based on the predicate.
109partition : (a -> Bool) -> [a] -> ([a],[a])
113 x::xs -> let (bs,cs) = partition pred xs in
114 if pred x then (x::bs,cs) else (bs,x::cs)
116-- Combine two lists, combining them into tuples pairwise.
117-- If one list is longer, the extra elements are dropped.
119-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
121zip : [a] -> [b] -> [(a,b)]
123-- Combine two lists, combining them with the given function.
124-- If one list is longer, the extra elements are dropped.
126-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
127zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
129-- Decompose a list of tuples.
130unzip : [(a,b)] -> ([a],[b])
134 (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
136-- Split a list with a given seperator.
138-- split "," "hello,there,friend" == ["hello", "there", "friend"]
139split : [a] -> [a] -> [[a]]
141-- Places the given value between all of the lists in the second argument
142-- and concatenates the result.
144-- join "a" ["H","w","ii","n"] == "Hawaiian"
145join : Appendable a -> [Appendable a] -> Appendable a
147-- Places the given value between all members of the given list.
149-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
150intersperse : a -> [a] -> [a]
153 a::b::cs -> a :: sep :: intersperse sep (b::cs)
157-- Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])`
158take : Int -> [a] -> [a]
160-- Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])`
161drop : Int -> [a] -> [a]
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