Module:Enum/doc
< Module:Enum
Revision as of 19:07, 3 October 2022 by Jacmob (talk | contribs) (Created page with "{{Documentation}} {{Helper module |name = Enum |fname1 = <nowiki>any(enum, [fn], [clone|false])</nowiki> |ftype1 = table, function/nil, boolean/nil |fuse1 = Loops over the array part of <code>enum</code> and passes each element as the first argument to <code>fn</code>. If <code>fn</code> returns <code>true</code> for at least one element then <code>any()</code> returns <code>true</code>, otherwise <code>false</code>. If no function is given <code>function(item) return it...")
This is the documentation page for Module:Enum
Module:Enum requires Module:LibraryUtil.
Module:Enum is required by Module:DependencyList.
This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See Near-Reality:Lua/Helper modules for a full list and more information.
Module | Function | Type | Use |
---|---|---|---|
Enum | any(enum, [fn], [clone|false]) | table, function/nil, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . If fn returns true for at least one element then any() returns true , otherwise false . If no function is given function(item) return item end is used. If clone is true the input enum is deep copied using mw.clone() before use. |
all(enum, [fn], [clone|false]) | table, function/nil, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . If fn returns true for all elements then all() returns true , otherwise false . If no function is given function(item) return item end is used. | |
each(enum, fn, [clone|false]) | table, function, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . This function returns nothing. | |
sum(enum, [clone|false]) | table, boolean/nil | Returns the sum of all array elements in enum . | |
reduce(enum, fn, [accumulator|enum[1]], [clone|false]) | table, function, any, boolean/nil | Loops over the array part of enum and passes each element as the first argument and accumulator as the second to fn . The return value of fn becomes the new accumulator . The final value of accumulator is returned. If no accumulator is given then the first element in enum is used. | |
scan(enum, fn, [accumulator|enum[1]], [clone|false]) | table, function, any, boolean/nil | Same as reduce() but each step is appended to a table. This table is then returned. | |
find(enum, fn, [default|nil], [clone|false]) | table, function, any, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . The first element where fn returns true is returned. If no elements passes the test, default is returned. | |
find_index(enum, fn, [default|nil], [clone|false]) | table, function, any, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . The index of the first element where fn returns true is returned. If no elements passes the test, default is returned. | |
max_by(enum, fn, [clone|false]) | table, function, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . max_by() returns two values, the first is the element where fn returned the largest value, the second is this largest value. The > operator is used for the comparisons. | |
map(enum, fn, [clone|false]) | table, function, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . The return value of fn is appended to a new table. This new table is returned. | |
filter(enum, [fn], [clone|false]) | table, function/nil, boolean/nil | Loops over the array part of enum and passes each element as the first argument to fn . If fn returns true the corresponding element is copied to a new table which is then returned. If no function is given function(item) return item end is used. | |
reject(enum, [fn], [clone|false]) | table, function, boolean/nil | The opposite of filter() . | |
split(enum, count, [clone|false]) | table, number, boolean/nil | Returns two tables where the first is equivalent to slice(enum, 1, count) and the second slice(enum, count+1, #enum) . | |
slice(enum, [start|1], [stop|#enum], [clone|false]) | table, number/nil, number/nil, boolean/nil | Returns a table containing all the elements of enum between the start and stop indices. The start and stop indices are inclusive. | |
take(enum, count, [clone|false]) | table, number, boolean/nil | Returns only the first table of split(enum, count) . | |
take_every(enum, n, [clone|false]) | table, number, boolean/nil | Returns a table containing every nth element of enum . | |
unique(enum, [fn], [clone|false]) | table, function/nil, boolean/nil | Returns a new table where all duplicate values in enum are removed. In case a duplicate is present, the element with the lowest index will be kept and every subsequent duplicate element is removed. fn can be used to create a custom id for every element so that the result is a table with elements which all create a unique id. If no function is given function(item) return item end is used. | |
zip(enums, [clone|false]) | table, boolean/nil | Groups elements with the same indexes from different arrays together, i.e. zip{ {a1, a2, a3}, {b1, b2, b3}, {c1, c2} } -> {{a1, b1, c1}, {a2, b2, c2}, {a3, b3}} | |
intersect(enum1, enum2, [clone|false]) | table, table, boolean/nil | Returns true if both sets have at least one element with equal values. | |
contains(enum, elem, [clone|false]) | table, any, boolean/nil | Returns true if enum contains elem , otherwise returns false. | |
take_from(enum, index, count) | table, number, number | Returns count number of elements, starting at index |