Module:ListUtil/doc

Lua metamodule containing higher-order functions for sequence tables.


 * : List-like table that is assumed to contain only non-nil values from  to   for some positive integer N.
 * : Function which accepts a value from a table as its first argument and the value's corresponding key as its second argument.
 * : Predicate which accepts a value from a table as its first argument and the value's corresponding key as its second argument. Only truthiness of the return value is considered.
 * : Function which accepts two table elements.

Generation

 * range (i, j, k)
 * Returns a table whose entries are the values produced by the Lua for-loop .   defaults to 1 if   and -1 otherwise if not given.


 * generate (n, f)
 * Returns.


 * array (x, ...)
 * Returns a multi-dimensional array with ranks  and all elements.

Counting

 * any (t, pr)
 * Returns true if  is true for any element of.


 * all (t, pr)
 * Returns true if  is true for all elements of.


 * none (t, pr)
 * Returns true if  is true for none of the elements of.


 * count (t, x)
 * Returns the number of elements of  that compare equal to.


 * count_if (t, pr)
 * Returns the number of elements of  that satisfy.

Searching

 * find (t, x)
 * Returns the key-value pair of the table's first element that compares equal to, or   if none can be found.


 * find_if (t, pr)
 * Returns the key-value pair of the table's first element that satisfies, or   if none can be found.


 * rfind (t, x)
 * Returns the key-value pair of the table's last element that compares equal to, or   if none can be found.


 * rfind_if (t, pr)
 * Returns the key-value pair of the table's last element that satisfies, or   if none can be found.

Comparison

 * equal (t1, t2)
 * Returns true if the two tables have equal sizes and their elements compare equal to each other.


 * compare (t1, t2)
 * Returns the lexicographical order between the two tables: -1 if, 1 if  , 0 if the two tables compare equal.

Transformation

 * reverse (t)
 * Returns a new table with the elements of  in reversed order.


 * reverse_self (t)
 * Reverses the order of the elements of . Returns.


 * sub (t, i, j)
 * Returns a subsequence of the table.  and   may be negative values and are adjusted in the same way as.


 * map (t, f)
 * Returns a new table with the results of calling  on each element of.


 * map_self (t, f)
 * Replaces every element of  with the result of calling   on it. Returns.


 * zip (t1, t2, op)
 * Returns a new table with the results of calling  on each element of   and the corresponding element of   with the same key.


 * select (t, pr)
 * Returns a new table containing only the elements of  that satisfy.


 * concat (t1, t2)
 * Returns a new table with all elements from  followed by all elements from.


 * concat_self (t1, t2)
 * Inserts all elements of  to   in the same order. Returns.


 * to_set (t)
 * Returns a new table where the elements of  all map to.

Other

 * reduce (t, op)
 * Returns the left fold of the first element of the table over the other elements, i.e..


 * reduce (t, op, z)
 * Returns the left fold of  over the elements of the table.


 * group_by (t, f)
 * Returns a new table in which the keys are the results of calling  on the elements of the table, and the values are lists of elements whose results compare equal to the corresponding keys.