Combine three lists of the same length elementwise using some function.
the function to combine elements with
the first list
the second list
the third list
a proof that the lengths of the first two inputs are equal
a proof that the lengths of the second and third inputs are equal
Combine two lists of the same length elementwise using some function.
the function to combine elements with
the first list
the second list
a proof that the lengths of the inputs are equal
Combine three lists elementwise into tuples
Combine two lists elementwise into pairs
Split a list of triples into three lists
Split a list of pairs into two lists
The unionBy function returns the union of two lists by user-supplied equality predicate.
Compute the union of two lists according to their Eq
instance.
union ['d', 'o', 'g'] ['c', 'o', 'w']
Transposes rows and columns of a list of lists.
with List transpose [[1, 2], [3, 4]]
This also works for non square scenarios, thus
involution does not always hold:
transpose [[], [1, 2]] = [[1], [2]]
transpose (transpose [[], [1, 2]]) = [[1, 2]]
TODO: Solution which satisfies the totality checker?
Convert any Foldable structure to a list.
Take the longest prefix of a list such that all elements satisfy some
Boolean predicate.
the predicate
Take the first n
elements of xs
If there are not enough elements, return the whole list.
how many elements to take
the list to take them from
The tails function returns all final segments of the argument, longest
first. For example,
tails [1,2,3] == [[1,2,3], [2,3], [3], []]
Attempt to get the tail of a list.
If the list is empty, return Nothing
.
Get the tail of a non-empty list.
proof that the list is non-empty
Split on the given element.
splitOn 0 [1,0,2,0,0,3]
A tuple where the first element is a List of the n first elements and
the second element is a List of the remaining elements of the list
It is equivalent to (take n xs, drop n xs)
the index to split at
the list to split in two
Split on any elements that satisfy the given predicate.
split (<2) [2,0,3,1,4]
Given a list and a predicate, returns a pair consisting of the longest
prefix of the list that satisfies a predicate and the rest of the list.
span (<3) [1,2,3,2,1]
Return the elements of a list in reverse order.
Construct a list with n
copies of x
how many copies
the element to replicate
Replaces all occurences of the first argument with the second argument in a list.
replaceOn '-' ',' ['1', '-', '2', '-', '3']
The partition function takes a predicate a list and returns the pair of lists of elements which do and do not satisfy the predicate, respectively; e.g.,
partition (<3) [0, 1, 2, 3, 4, 5]
The nubBy function behaves just like nub, except it uses a user-supplied equality predicate instead of the overloaded == function.
O(n^2). The nub function removes duplicate elements from a list. In
particular, it keeps only the first occurrence of each element. It is a
special case of nubBy, which allows the programmer to supply their own
equality test.
nub (the (List _) [1,2,1,3])
Mapping a function over a list doesn't change its length.
Apply a partial function to the elements of a list, keeping the ones at which
it is defined.
Mapping two functions is the same as mapping their composition.
Mapping a function over two lists and appending them is equivalent
to appending them and then mapping the function.
Find associated information in a list using a custom comparison.
Find associated information in a list using Boolean equality.
Either return the head of a list, or Nothing
if it is empty.
Simply-typed recursion operator for lists.
what to return at the end of the list
what to do at each step of recursion
the list to recurse over
The length of two lists that are appended is the sum of the lengths
of the input lists.
Compute the length of a list.
Runs in linear time
Attempt to retrieve the last element of a non-empty list.
If the list is empty, return Nothing
.
Retrieve the last element of a non-empty list.
proof that the list is non-empty
The isSuffixOf function takes two lists and returns True iff the first list is a suffix of the second.
The isPrefixOf function takes two lists and returns True iff the first list is a prefix of the second.
Returns True
iff the argument is empty
The isInfixOf function takes two lists and returns True iff the first list is contained, wholly and intact, anywhere within the second.
isInfixOf ['b','c'] ['a', 'b', 'c', 'd']
isInfixOf ['b','d'] ['a', 'b', 'c', 'd']
Returns True
iff the argument is not empty
Insert some separator between the elements of a list.
with List (intersperse ',' ['a', 'b', 'c', 'd', 'e'])
The inits function returns all initial segments of the argument, shortest
first. For example,
inits [1,2,3]
Attempt to Return all but the last element of a list.
If the list is empty, return Nothing
.
Return all but the last element of a non-empty list.
proof that the list is non-empty
Attempt to find a particular element of a list.
If the provided index is out of bounds, return Nothing.
Find a particular element of a list.
a proof that the index is within bounds
Attempt to get the first element of a list. If the list is empty, return
Nothing
.
Get the first element of a non-empty list
proof that the list is non-empty
No list contains an element of the empty list.
No list contains an element of the empty list by any predicate.
Check if any elements of the first list are found in the second, using
a custom comparison.
Check if any elements of the first list are found in the second, using
Boolean equality.
The definition of foldl works the same as the default definition
in terms of foldr
Find the indices of all elements that satisfy some predicate.
Find the index of the first element of a list that satisfies a predicate, or
Nothing
if none do.
Find the first element of a list that satisfies a predicate, or Nothing
if none do.
filter, applied to a predicate and a list, returns the list of those elements that satisfy the predicate; e.g.,
filter (< 3) [Z, S Z, S (S Z), S (S (S Z)), S (S (S (S Z)))]
Check if something is a member of a list using a custom comparison.
Check if something is a member of a list using the default Boolean equality.
Remove the longest prefix of a list such that all removed elements satisfy some
Boolean predicate.
the predicate
Drop the first n
elements of xs
If there are not enough elements, return the empty list.
how many elements to drop
the list to drop them from
The deleteBy function behaves like delete, but takes a user-supplied equality predicate.
delete x
removes the first occurrence of x
from its list argument. For
example,
delete 'a' ['b', 'a', 'n', 'a', 'n', 'a']
It is a special case of deleteBy, which allows the programmer to supply
their own equality test.
Given a list and a predicate, returns a pair consisting of the longest
prefix of the list that does not satisfy a predicate and the rest of the
list.
break (>=3) [1,2,3,2,1]
The empty list is a right identity for append.
Appending lists is associative.
The \\
function is list difference (non-associative). In the result of
xs \\ ys
, the first occurrence of each element of ys in turn (if any) has
been removed from xs
, e.g.,
(([1,2] ++ [2,3]) \\ [1,2])
Linked lists
Append two lists