List

every value in a list must have the same type

isEmpty : List a -> Bool
length : List a -> Int
reverse : List a -> List a
member : a -> List a -> Bool

tail : List a -> Maybe (List a)
head : List a -> Maybe a

filter : (a -> Bool) -> List a -> List a
take : Int -> List a -> List a
drop : Int -> List a -> List a

singleton : a -> List a
repeat : Int -> a -> List a

repeat 3 (0,0) == [(0,0),(0,0),(0,0)]

range : Int -> Int -> List Int

range 3 6 == [3, 4, 5, 6] range 3 3 == [3] range 6 3 == []

(::) : a -> List a -> List a
append : List a -> List a -> List a
concat : List (List a) -> List a

intersperse : a -> List a -> List a

intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]

partition : (a -> Bool) -> List a -> (List a, List a)
the first list contains all values that satisfy the predicate, and the second list contains all the value that do not

partition (\x -> x < 3) [0,1,2,3,4,5] == ([0,1,2], [3,4,5])
partition isEven [0,1,2,3,4,5] == ([0,2,4], [1,3,5])

unzip : List (a, b) -> (List a, List b)

unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])

pairs : List a -> List b -> List (a,b)

map : (a -> b) -> List a -> List b
map2 , map3 , map4 , map5

filterMap : (a -> Maybe b) -> List a -> List b
apply a function that may succeed to all values in the list, but only keep the successes

onlyTeens = filterMap isTeen [3, 15, 12, 18, 24] == [15, 18]

isTeen : Int -> Maybe Int
isTeen n = if 13 <= n && n <= 19 then Just n else Nothing

concatMap : (a -> List b) -> List a -> List b
map a given function onto a list and flatten the resulting lists

concatMap f xs == concat (map f xs)

indexedMap : (Int -> a -> b) -> List a -> List b
same as map but the function is also applied to the index of each element (starting at zero)

indexedMap (,) ["Tom","Sue","Bob"] == [ (0,"Tom"), (1,"Sue"), (2,"Bob") ]

foldr : (a -> b -> b) -> b -> List a -> b

foldl : (a -> b -> b) -> b -> List a -> b

sum : List number -> number

product : List number -> number

maximum : List comparable -> Maybe comparable
find the maximum element in a non-empty list

maximum [1,4,2] == Just 4
maximum []      == Nothing

minimum : List comparable -> Maybe comparable
find the minimum element in a non-empty list

minimum [3,2,1] == Just 1
minimum []      == Nothing

all : (a -> Bool) -> List a -> Bool
determine if all elements satisfy the predicate

all isEven [2,4] == True
all isEven [2,3] == False
all isEven [] == True

any : (a -> Bool) -> List a -> Bool
determine if any elements satisfy the predicate

any isEven [2,3] == True
any isEven [1,3] == False
any isEven [] == False

scanl : (a -> b -> b) -> b -> List a -> List b
reduce a list from the left, building up all of the intermediate results into a list

scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]

sort : List comparable -> List comparable
sort values from lowest to highest

sortBy : (a -> comparable) -> List a -> List a
sort values by a derived property

alice = { name="Alice", height=1.62 }
bob   = { name="Bob"  , height=1.85 }
chuck = { name="Chuck", height=1.76 }

sortBy .name   [chuck,alice,bob] == [alice,bob,chuck]
sortBy .height [chuck,alice,bob] == [alice,chuck,bob]

sortBy String.length ["mouse","cat"] == ["cat","mouse"]

sortWith : (a -> a -> Order) -> List a -> List a
sort values with a custom comparison function. This is the most general sort function, allowing you to define any other