Listext.List
is_sorted cmp l
returns whether l
is sorted according to cmp
.
take n list
returns the first n
elements of list
(or less if list is shorter).
drop n list
returns the list without the first n
elements of list
(or if list is shorter).
rev_map f l
gives the same result as Stdlib
.List.rev (
Stdlib
.List.mapi f l)
, but is tail-recursive and more efficient.
map_tr f l
is Stdlib
.List.rev (
Stdlib
.List.rev_map f l)
.
mapi_tr f l
is Stdlib
.List.rev (
rev_mapi
f l)
.
Count the number of list elements matching the given predicate.
Find the indices of all elements matching the given predicate.
iteri_right f l
is Stdlib
.List.iteri f (
Stdlib
.List.rev l)
find_minimum cmp l
returns the lowest element in l
according to the sort order of cmp
, or None
if the list is empty. When two ore more elements match the lowest value, the left-most is returned.
chop k l
splits l
at index k
to return a pair of lists. Raises invalid_arg when i
is negative or greater than the length of l
.
rev_chop k l
splits l
at index k
to return a pair of lists, the first in reverse order. Raises invalid_arg when i
is negative or greater than the length of l
.
Tail-recursive chop
.
dice k l
splits l
into lists with k
elements each. Raises Invalid_arg
if List.length l
is not divisible by k
.
sub from to l
returns the sub-list of l
that starts at index from
and ends at to
or an empty list if to
is equal or less than from
. Negative indices are treated as 0 and indeces higher than List.length l
- 1
are treated as List.length l - 1
.
Replace the element at the given index with the given value.
Apply the given function to the element at the given index.
Act as List.assoc, but return the given default value if the key is not in the list.
Replace the value belonging to a key in an association list. Adds the key/value pair if it does not yet exist in the list. If the same key occurs multiple time in the original list, all occurances are removed and replaced by a single new key/value pair. This function is useful is the assoc list is used as a lightweight map/hashtable/dictonary.
Includes everything from update
and all key/value pairs from existing
for which the key does not exist in update
. In other words, it is like replace_assoc
but then given a whole assoc list of updates rather than a single key/value pair.
map_assoc_with_key op al
transforms every value in al
based on the key and the value using op
.
Perform a lookup on an association list of (value, key) pairs.
restrict_with_default default keys al
makes a new association map from keys
to previous values for keys
in al
. If a key is not found in al
, the default
is used.
There are no known users of these functions.
These are usually useful for coding challenges like Advent of Code.
range lower upper = lower; lower + 1; ...; upper - 1
Returns the empty list if lower >= upper. Consider building an Stdlib
.Seq, it's more flexible
Tail-recursive between
.
val inner :
(('a -> 'b -> 'c -> 'd) -> 'e -> 'f -> 'g -> 'h) ->
'e ->
('b -> 'c -> 'i) ->
'f ->
'g ->
('a -> 'i -> 'd) ->
'h
Compute the inner product of two lists.
Please use Set.Make instead, these functions have quadratic costs!
setify a
removes all duplicates from a
while maintaining order. Please use List.sort_uniq
instead to deduplicate lists if possible
subset a b
returns whether all elements in b
can be found in a