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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:Enum

Information icon-grey.png
This is a documentation subpage for Module:Enum.
It contains usage information, categories, and other content that is not part of the original module page.
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.

ModuleFunctionTypeUse
Enumany(enum, [fn], [clone|false])table, function/nil, boolean/nilLoops 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/nilLoops 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/nilLoops 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/nilReturns the sum of all array elements in enum.
reduce(enum, fn, [accumulator|enum[1]], [clone|false])table, function, any, boolean/nilLoops 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/nilSame 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/nilLoops 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/nilLoops 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/nilLoops 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/nilLoops 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/nilLoops 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/nilThe opposite of filter().
split(enum, count, [clone|false])table, number, boolean/nilReturns 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/nilReturns 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/nilReturns only the first table of split(enum, count).
take_every(enum, n, [clone|false])table, number, boolean/nilReturns a table containing every nth element of enum.
unique(enum, [fn], [clone|false])table, function/nil, boolean/nilReturns 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/nilGroups 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/nilReturns true if both sets have at least one element with equal values.
contains(enum, elem, [clone|false])table, any, boolean/nilReturns true if enum contains elem, otherwise returns false.
take_from(enum, index, count)table, number, numberReturns count number of elements, starting at index