Combine three lists elementwise using some function. If they are different
lengths, the result is truncated to the length of the shortest list.
the function to combine elements with
the first list
the second list
the third list
Combine two lists elementwise using some function. If they are different
lengths, the result is truncated to the length of the shorter list.
the function to combine elements with
the first list
the second list
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
implementation.
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]
Check whether a list is sorted with respect to the default ordering for the type of its elements.
Sort a list using some arbitrary comparison predicate.
how to compare elements
the list to sort
Sort a list using the default ordering for the type of its elements.
The scanl1 function is a variant of scanl that doesn't require an explicit
starting value.
It assumes the first element of the list to be the starting value and then
starts the fold with the element following it.
scanl1 (+) [1,2,3,4]
The scanl function is similar to foldl, but returns all the intermediate
accumulator states in the form of a list.
scanl (+) 0 [1,2,3,4]
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])
Decide whether a list is non-empty
Merge two sorted lists using an arbitrary comparison
predicate. Note that the lists must have been sorted using this
predicate already.
Merge two sorted lists using the default ordering for the type of their elements.
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.
Check whether a list is a prefix of another according to a user-supplied equality test.
the equality comparison
the potential prefix
the list that may have left
as its prefix
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'])
Given a separator list and some more lists, produce a new list by
placing the separator between each of the lists.
the separator
the lists between which the separator will be placed
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
Decide whether k
is a valid index into xs
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
Implement foldl using foldr, for a later equality proof.
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.
A filtered list is no longer than its input
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)))]
Find all indices for an element in a list, using a custom equality test.
Find all indices for an element in a list, using the default equality test for the type of list elements.
Find the index of the first occurrence of an element in a list, using a custom equality test.
Find the index of the first occurrence of an element in a list,
using the default equality test for the type of list elements.
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.
Keep the Just
elements in a list, discarding the Nothing
elements.
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])
Satisfiable if xs
is non-empty (e.g., if xs
is a cons).
Generic lists
Satisfiable if k
is a valid index into xs
the potential index
the list into which k may be an index
Append two lists