5import Native.List as Native
7-- Add an element to the front of a list `(1 :: [2,3] == [1,2,3])`
11-- Puts two appendable things together:
13-- [1,1] ++ [2,3] == [1,1,2,3]
14-- "abc" ++ "123" == "abc123"
15(++) : appendable -> appendable -> appendable
18-- Extract the first element of a list. List must be non-empty.
19-- `(head [1,2,3] == 1)`
23-- Extract the elements after the head of the list. List must be non-empty.
24-- `(tail [1,2,3] == [2,3])`
28-- Extract the last element of a list. List must be non-empty.
29-- `(last [1,2,3] == 3)`
33-- Check if a list is empty `(isEmpty [] == True)`
40-- Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])`
41map : (a -> b) -> [a] -> [b]
44-- Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")`
45foldl : (a -> b -> b) -> b -> [a] -> b
48-- Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)`
49foldr : (a -> b -> b) -> b -> [a] -> b
52-- Reduce a list from the left without a base case. List must be non-empty.
53foldl1 : (a -> a -> a) -> [a] -> a
56-- Reduce a list from the right without a base case. List must be non-empty.
57foldr1 : (a -> a -> a) -> [a] -> a
60-- Reduce a list from the left, building up all of the intermediate results into a list.
62-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
63scanl : (a -> b -> b) -> b -> [a] -> [b]
66-- Same as scanl but it doesn't require a base case. List must be non-empty.
68-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
69scanl1 : (a -> a -> a) -> [a] -> [a]
72-- Filter out elements which do not satisfy the predicate: `(filter isLower "AaBbCc" == "abc")`
73filter : (a -> Bool) -> [a] -> [a]
76-- Determine the length of a list: `(length "innumerable" == 11)`
80-- Reverse a list. `(reverse [1..4] == [4,3,2,1])`
82reverse = Native.reverse
84-- Check to see if all elements satisfy the predicate.
85all : (a -> Bool) -> [a] -> Bool
88-- Check to see if any elements satisfy the predicate.
89any : (a -> Bool) -> [a] -> Bool
92-- Check to see if all elements are True.
96-- Check to see if any elements are True.
100-- Concatenate a list of appendable things:
102-- concat ["tree","house"] == "treehouse"
103concat : [appendable] -> appendable
104concat = Native.concat
106-- Map a given function onto a list and flatten the resulting lists.
108-- concatMap f xs == concat (map f xs)
109concatMap : (a -> appendable) -> [a] -> appendable
110concatMap f list = concat (map f list)
112-- Get the sum of the list elements. `(sum [1..4] == 10)`
113sum : [number] -> number
116-- Get the product of the list elements. `(product [1..4] == 24)`
117product : [number] -> number
120-- Find the maximum element in a non-empty list: `maximum [1,4,2] == 4`
121maximum : [comparable] -> comparable
124-- Find the minimum element in a non-empty list: `minimum [3,2,1] == 1`
125minimum : [comparable] -> comparable
128-- Split a list based on the predicate.
129partition : (a -> Bool) -> [a] -> ([a],[a])
133 x::xs -> let (bs,cs) = partition pred xs in
134 if pred x then (x::bs,cs) else (bs,x::cs)
136-- Combine two lists, combining them into tuples pairwise.
137-- If one list is longer, the extra elements are dropped.
139-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
141zip : [a] -> [b] -> [(a,b)]
144-- Combine two lists, combining them with the given function.
145-- If one list is longer, the extra elements are dropped.
147-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
148zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
149zipWith = Native.zipWith
151-- Decompose a list of tuples.
152unzip : [(a,b)] -> ([a],[b])
156 (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
158-- Split a list with a given seperator.
160-- split "," "hello,there,friend" == ["hello", "there", "friend"]
161split : [a] -> [a] -> [[a]]
164-- Places the given value between all of the lists in the second argument
165-- and concatenates the result.
167-- join "a" ["H","w","ii","n"] == "Hawaiian"
168join : appendable -> [appendable] -> appendable
171-- Places the given value between all members of the given list.
173-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
174intersperse : a -> [a] -> [a]
177 a::b::cs -> a :: sep :: intersperse sep (b::cs)
181-- Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])`
182take : Int -> [a] -> [a]
185-- Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])`
186drop : 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