head :: [a] -> a { } #
last :: [a] -> a { } #
O(n). Extract the last element of a list.
tail :: [a] -> [a] { } #
O(1). Extract the elements after the head of a list.
init :: [a] -> [a] { } #
O(n). Return all elements except the last one.
uncons :: [a] -> Maybe (a, [a]) { } #
O(1). Decompose a list into its head and tail.
unsnoc :: [a] -> Maybe ([a], a) { } #
O(n). Decompose a list into its init and last.
null :: [a] -> Bool { } #
O(1). Test whether a list is empty.
length :: [a] -> Int { } #
O(n). Return the length of a list.
++ :: [a] -> [a] -> [a] { } #
O(n). Append two lists.
ys :: { } #
map :: (a -> b) -> [a] -> [b] { } #
O(n). Apply a function to each element.
reverse :: [a] -> [a] { } #
O(n). Reverse a list.
intersperse :: a -> [a] -> [a] { } #
O(n). Insert an element between each pair.
intercalate :: [a] -> [[a]] -> [a] { } #
O(n). Insert a list between each pair of lists.
transpose :: [[a]] -> [[a]] { } #
Transpose rows and columns.
subsequences :: [a] -> [[a]] { } #
All subsequences (power set).
permutations :: [a] -> [[a]] { } #
All permutations.
foldl :: (b -> a -> b) -> b -> [a] -> b { } #
O(n). Left-associative fold.
foldl' :: (b -> a -> b) -> b -> [a] -> b { } #
O(n). Strict left-associative fold.
foldl1 :: (a -> a -> a) -> [a] -> a { } #
O(n). Left fold with no initial value.
foldl1' :: (a -> a -> a) -> [a] -> a { } #
O(n). Strict left fold with no initial value.
foldr :: (a -> b -> b) -> b -> [a] -> b { } #
O(n). Right-associative fold.
foldr1 :: (a -> a -> a) -> [a] -> a { } #
O(n). Right fold with no initial value.
concat :: [[a]] -> [a] { } #
O(n). Concatenate a list of lists.
concatMap :: (a -> [b]) -> [a] -> [b] { } #
O(n). Map a function over a list and concatenate the results.
and :: [Bool] -> Bool { } #
O(n). Conjunction of a list of booleans.
or :: [Bool] -> Bool { } #
O(n). Disjunction of a list of booleans.
any :: (a -> Bool) -> [a] -> Bool { } #
O(n). Test whether any element satisfies the predicate.
all :: (a -> Bool) -> [a] -> Bool { } #
O(n). Test whether all elements satisfy the predicate.
sum :: (Num a) => [a] -> a { } #
O(n). Sum of a list of numbers.
product :: (Num a) => [a] -> a { } #
O(n). Product of a list of numbers.
maximum :: (Ord a) => [a] -> a { } #
O(n). Maximum element of a non-empty list.
minimum :: (Ord a) => [a] -> a { } #
O(n). Minimum element of a non-empty list.
maximumBy :: (a -> a -> Ordering) -> [a] -> a { } #
O(n). Maximum element using a custom comparison function.
minimumBy :: (a -> a -> Ordering) -> [a] -> a { } #
O(n). Minimum element using a custom comparison function.
scanl :: (b -> a -> b) -> b -> [a] -> [b] { } #
O(n). Left-to-right scan, returning all intermediate values.
scanl' :: (b -> a -> b) -> b -> [a] -> [b] { } #
O(n). Strict version of scanl.
scanl1 :: (a -> a -> a) -> [a] -> [a] { } #
O(n). scanl with no starting value.
scanr :: (a -> b -> b) -> b -> [a] -> [b] { } #
O(n). Right-to-left scan.
scanr1 :: (a -> a -> a) -> [a] -> [a] { } #
mapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y]) { } #
mapAccumR :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y]) { } #
O(n). Map with an accumulating parameter, right to left.
iterate :: (a -> a) -> a -> [a] { } #
Build an infinite list by repeated application.
iterate' :: (a -> a) -> a -> [a] { } #
Strict version of iterate.
repeat :: a -> [a] { } #
An infinite list of the same value.
replicate :: Int -> a -> [a] { } #
O(n). @replicate n x@ is a list of length @n@ with @x@ as each element.
cycle :: [a] -> [a] { } #
Infinite repetition of a list.
unfoldr :: (b -> Maybe (a, b)) -> b -> [a] { } #
Build a list from a seed value.
take :: Int -> [a] -> [a] { } #
O(n). Take the first @n@ elements.
drop :: Int -> [a] -> [a] { } #
O(n). Drop the first @n@ elements.
splitAt :: Int -> [a] -> ([a], [a]) { } #
O(n). @splitAt n xs == (take n xs, drop n xs)@.
takeWhile :: (a -> Bool) -> [a] -> [a] { } #
O(n). Take elements while the predicate holds.
dropWhile :: (a -> Bool) -> [a] -> [a] { } #
O(n). Drop elements while the predicate holds.
dropWhileEnd :: (a -> Bool) -> [a] -> [a] { } #
O(n). Drop trailing elements while the predicate holds.
span :: (a -> Bool) -> [a] -> ([a], [a]) { } #
O(n). Split at the first element that fails the predicate.
otherwise :: { } #
break :: (a -> Bool) -> [a] -> ([a], [a]) { } #
O(n). Split at the first element that satisfies the predicate.
stripPrefix :: (Eq a) => [a] -> [a] -> Maybe [a] { } #
O(n). Strip a prefix from a list. Returns Nothing if the prefix doesn't match.
group :: (Eq a) => [a] -> [[a]] { } #
O(n). Group adjacent equal elements.
groupBy :: (a -> a -> Bool) -> [a] -> [[a]] { } #
O(n). Group adjacent elements by a predicate.
inits :: [a] -> [[a]] { } #
O(n²). All initial segments of a list, shortest first.
tails :: [a] -> [[a]] { } #
O(n). All final segments of a list, longest first.
isPrefixOf :: (Eq a) => [a] -> [a] -> Bool { } #
O(n). Test whether the first list is a prefix of the second.
isSuffixOf :: (Eq a) => [a] -> [a] -> Bool { } #
O(n). Test whether the first list is a suffix of the second.
isInfixOf :: (Eq a) => [a] -> [a] -> Bool { } #
O(n*m). Test whether the first list is contained in the second.
isSubsequenceOf :: (Eq a) => [a] -> [a] -> Bool { } #
O(n+m). Test whether the first list is a subsequence of the second.
elem :: (Eq a) => a -> [a] -> Bool { } #
O(n). Test whether an element is in a list.
notElem :: (Eq a) => a -> [a] -> Bool { } #
O(n). Test whether an element is not in a list.
lookup :: (Eq a) => a -> [(a, b)] -> Maybe b { } #
O(n). Look up a key in an association list.
find :: (a -> Bool) -> [a] -> Maybe a { } #
O(n). Find the first element satisfying a predicate.
filter :: (a -> Bool) -> [a] -> [a] { } #
O(n). Return elements that satisfy the predicate.
partition :: (a -> Bool) -> [a] -> ([a], [a]) { } #
O(n). Partition a list by a predicate.
!? :: [a] -> Int -> Maybe a { } #
O(n). Safe indexing. Returns Nothing for out-of-bounds.
n :: { } #
!! :: [a] -> Int -> a { } #
O(n). Indexing. Throws an error for out-of-bounds or negative index.
n :: { } #
elemIndex :: (Eq a) => a -> [a] -> Maybe Int { } #
O(n). Find the index of the first occurrence of an element.
elemIndices :: (Eq a) => a -> [a] -> [Int] { } #
O(n). Find the indices of all occurrences of an element.
findIndex :: (a -> Bool) -> [a] -> Maybe Int { } #
O(n). Find the index of the first element satisfying a predicate.
findIndices :: (a -> Bool) -> [a] -> [Int] { } #
O(n). Find the indices of all elements satisfying a predicate.
zip :: [a] -> [b] -> [(a, b)] { } #
O(min(n,m)). Zip two lists into a list of pairs.
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)] { } #
zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)] { } #
zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)] { } #
zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)] { } #
zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)] { } #
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] { } #
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d] { } #
O(min(n,m,o)). Zip three lists with a combining function.
zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e] { } #
zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] { } #
zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] { } #
zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h] { } #
unzip :: [(a, b)] -> ([a], [b]) { } #
O(n). Unzip a list of pairs into two lists.
unzip3 :: [(a, b, c)] -> ([a], [b], [c]) { } #
O(n). Unzip a list of triples into three lists.
unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d]) { } #
Unzip a list of 4-tuples.
unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e]) { } #
Unzip a list of 5-tuples.
unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f]) { } #
Unzip a list of 6-tuples.
unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g]) { } #
Unzip a list of 7-tuples.
lines :: String -> [String] { } #
O(n). Split a string into lines, breaking on @\\n@.
words :: String -> [String] { } #
O(n). Split a string into words, breaking on whitespace.
unlines :: [String] -> String { } #
O(n). Join lines with newlines.
unwords :: [String] -> String { } #
O(n). Join words with spaces.
nub :: (Eq a) => [a] -> [a] { } #
O(n²). Remove duplicate elements, keeping the first occurrence.
nubBy :: (a -> a -> Bool) -> [a] -> [a] { } #
O(n²). Remove duplicates using a custom equality predicate.
delete :: (Eq a) => a -> [a] -> [a] { } #
O(n). Remove the first occurrence of an element.
deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] { } #
O(n). Remove the first occurrence using a custom equality predicate.
\\ :: (Eq a) => [a] -> [a] -> [a] { } #
O(n*m). List difference: elements of the first list not in the second.
union :: (Eq a) => [a] -> [a] -> [a] { } #
O(n*m). List union, preserving order and removing duplicates from the second list.
unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] { } #
O(n*m). List union using a custom equality predicate.
intersect :: (Eq a) => [a] -> [a] -> [a] { } #
O(n*m). List intersection.
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] { } #
O(n*m). List intersection using a custom equality predicate.
sort :: (Ord a) => [a] -> [a] { } #
O(n log n). Sort a list in ascending order.
sortBy :: (a -> a -> Ordering) -> [a] -> [a] { } #
O(n log n). Sort using a custom comparison function.
mergeAll :: { } #
mergePairs :: { } #
merge :: { } #
sortOn :: (Ord b) => (a -> b) -> [a] -> [a] { } #
O(n log n). Sort by comparing the results of a key function.
insert :: (Ord a) => a -> [a] -> [a] { } #
O(n). Insert an element into a sorted list, preserving the sort order.
insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a] { } #
O(n). Insert using a custom comparison function.
genericLength :: (Num i) => [a] -> i { } #
O(n). Length with a generic numeric result type.
genericTake :: (Integral i) => i -> [a] -> [a] { } #
O(n). Take with a generic integral index type.
genericDrop :: (Integral i) => i -> [a] -> [a] { } #
O(n). Drop with a generic integral index type.
genericSplitAt :: (Integral i) => i -> [a] -> ([a], [a]) { } #
O(n). Split with a generic integral index type.
genericIndex :: (Integral i) => [a] -> i -> a { } #
O(n). Indexing with a generic integral index type.
genericReplicate :: (Integral i) => i -> a -> [a] { } #
O(n). Replicate with a generic integral count type.
errorEmptyList :: String -> a { } #