Module:HashUtil/doc

Lua metamodule containing higher-order functions for non-sequence tables.


 * : Table which contains arbitrary key-value pairs.
 * : 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

 * from_lists (ks, vs)
 * Creates a table from a list of keys and a list of values. Later duplicate keys take precedence.


 * from_pairs (s, g)
 * Creates a table by calling  on each element of the sequence   and using its first two return values as a key-value pair.


 * generate (s, g)
 * Returns.

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 any of the table's elements that compares equal to, or   if none can be found.


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

Transformation

 * 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.


 * merge (t1, t2)
 * Returns a new table containing key-value pairs from both tables.  takes precedence.


 * merge_self (t1, t2)
 * Adds all key-value pairs from  to  . Returns.


 * invert (t)
 * Returns a new table with keys becoming values and values becoming keys. Duplicate keys are overwritten in an arbitrary order.


 * keys (t)
 * Returns a sequence containing the keys of the table in an arbitrary order.


 * values (t)
 * Returns a sequence containing the values of the table in an arbitrary order.


 * to_lists (t)
 * Returns . The orders from the two sequences are guaranteed to be the same.

Other

 * sorted_pairs (t)
 * Returns a generator which iterates through the key-value pairs of, sorted by keys with.
 * Equivalent to.


 * sorted_pairs (t, g)
 * Returns a generator which iterates through the key-value pairs of, sorted by  , which accepts the values of two pairs to compare followed by their corresponding keys.