Differenze tra le versioni di "Modulo:Wikilib/tables"

Jump to navigation Jump to search
Genral refactoring: added zip, flatten, values and new slice functionality *** sovrascritto il testo esistente ***
m (Adding copy and values)
(Genral refactoring: added zip, flatten, values and new slice functionality *** sovrascritto il testo esistente ***)
 
local t = {}
 
 
-- Stateless iterator on non-integer keys
repeat
nextKey, nextValue = next(tab, nextKey)
until type(nextKey) ~= 'number' or math.floor(nextKey) ~= nextKey
or math.floor(nextKey) ~= nextKey
return nextKey, nextValue
end
local next_non_int = nextNonInt -- luacheck: no unused
 
local next_non_int = nextNonInt -- luacheck: no unused
 
-- Stateless iterator to be used in for loops
table.nonIntPairs = function(tab)
return nextNonInt, tab
end
 
table.non_int_pairs = t.nonIntPairs
t.nonIntPairs, t.non_int_pairs =
table.nonIntPairs, table.nonIntPairs
 
-- Returns true only if a is lexigographically greater than b
end
 
-- Converting to number for better comparison (eg. '01' and 1)
--[[
Necessario affinché roba come 1 e
'01' siano considerati uguali
--]]
local nA, nB = tonumber(a), tonumber(b)
if nA and nB then
return tostring(a) < tostring(b)
end
 
 
--[[
 
Returns true if all of the elements in the list satisties a predicate.
Ricerca lineare: si passa una table e un valore e
 
restituisce il suo indice o nil
The predicate function takes the value as the first argument, then the key;
usual key-value order is reversed because the key is often unnecessary, and
having it last leads to nicer syntax in the call site.
 
TODO: refactoring to use just built-ins
 
--]]
table.searchall = function(tab, valuefunct, iter)
for k,return v in pairstable.fold(tab), dotrue,
if v ==function(acc, value, thenkey)
return kfunct(value, key) and acc
end, iter)
end
 
t.all = table.all
 
 
--[[
 
Returns true if at least one of the elements in the list satisties a predicate.
 
The predicate function takes the value as the first argument, then the key;
usual key-value order is reversed because the key is often unnecessary, and
having it last leads to nicer syntax in the call site.
 
TODO: refactoring to use just built-ins
 
--]]
table.any = function(tab, funct, iter)
return table.fold(tab, false,
function(acc, value, key)
return funct(value, key) or acc
end, iter)
end
t.any = table.any
 
 
--[[
 
Deep clones a table. It intentionally doesn't clone the metatables, as that's
the job of mw.clone.
 
--]]
table.copy = function(value)
local dest = {}
for k, v in pairs(value) do
dest[k] = type(v) == 'table' and table.copy(v) or v
end
return dest
end
t.copy = table.copy
 
 
--[[
 
Merges two tables into a new one. Integer indices of the second table will
follow the ones of the first. Other indices overwrite the ones of the first
in case of equlity, unless the values are tables in both the source tables:
in this case they are merged recursively.
 
--]]
table.deepMerge = function(tab1, tab2)
-- Better to use mw.clone, so as to keep metatable of items.
local dest = mw.clone(tab1)
 
-- Double loop to keep integer keys sorted
for _, value in ipairs(tab2) do
table.insert(dest, value)
end
for key, value in table.nonIntPairs(tab2) do
if dest[key]
and type(dest[key]) == 'table'
and type(value) == 'table'
then
dest[key] = table.deepMerge(dest[key], value)
else
dest[key] = value
end
end
-- No explicit return, thus nildest
end
table.deep_merge = table.deepMerge
t.deep_merge, t.deepMerge = table.deepMerge, table.deepMerge
 
table.linearSearch, table.linear_search =
table.search, table.search
t.search, t.linearSearch, t.linear_search =
table.search, table.search, table.search
 
--[[
 
Recursive search: looks for a value in a table and possible subtables. Returns
Ricerca ricorsiva: cerca un valore in una table e
a list of indices, mapping the nesting of tables. This means that the last
in eventuali subtables. Ritorna una lista di indici,
index is the one of the element, the second last is the subtable it is found
l'ultimo per l'elemento, i precedenti per le subtables.
in, the third last the subtable that contains such table an so on. If the
Se l'elemento non è presente, ritorna nil
element is not found, returns nil.
 
Example:
Esempio: t.deep_search({'a', {'b', 'c'}}, 'b') --> 2, 1
table.deep_search({'a', {'b', 'c'}}, 'b') --> 2, 1
 
--]]
-- No explicit return, thus nil
end
table.deep_search = table.deepSearch
t.deepSearch, t.deep_search = table.deepSearch, table.deepSearch
 
table.deep_search, table.recursiveSearch, table.recursive_search =
table.deepSearch, table.deepSearch, table.deepSearch
t.deepSearch, t.deep_search, t.recursiveSearch, t.recursive_search =
table.deepSearch, table.deepSearch, table.deepSearch, table.deepSearch
 
--[[
 
Returns whether two tables are equal: this means same keys mapped to same
Ritorna il numero di elementi di una table,
values, where same is the == operator. For the sake of conveniente, it returns
solo quelli con indici numerici se il secondo
true also for non-table arguments, as long as they computer equals.
argomento è true o 'num', altrimenti anche
quelli con indice diverso.
 
--]]
table.getnequal = function(selftab1, counttab2)
--[[
count = count or 'all'
Arguments are compared directly if:
local n = 0
- One of them has the __eq metamethod
local iterator
- One of them is not a table
if count == true or tostring(count):lower() == 'num' then
--]]
iterator = ipairs
local mt1 = getmetatable(tab1)
else
local mt2 = getmetatable(tab2)
iterator = pairs
if mt1 and mt1.__eq or mt2 and mt2.__eq
or type(tab1) ~= 'table'
or type(tab2) ~= 'table' then
return tab1 == tab2
end
 
for _ in iterator(self) do
-- Optimization: references to the same table can be assessed equal here
n = n + 1
if tab1 == tab2 then
return true
end
return n
end
 
--[[
t.getn = table.getn
If the two tables have different number of items, they aren't equal.
 
Furthermore, it covers the cases in which:
--[[
- tab1 is empty, and the upcoming loop doesn't run at all.
- tab1 is a subset of tab2, not covered by the loop, since only
tab1 indices are used.
--]]
if table.getn(tab1) ~= table.getn(tab2) then
return false
end
 
for key, value in pairs(tab1) do
Aggiunge elementi ad una table che sono alias di altri elementi della stessa table.
-- Easerie to compare this way, being table.equal very type-safe
Il primo argomento è la table in questione; il secondo una table contenente le
if not table.equal(value, tab2[key]) then
chiavi degli elementi di cui si vogliono creare gli alias; il terzo una table
return false
di cui ogni elemento è a sua volta una table, che contiene le chiavi degli alias
relativi all'elemento di indice uguale nel secondo argomento.
Esempio di chiamata:
table.tableKeysAlias(t, {'key', 'key1'}, {{'alias', alias1'}, {'alias2', 'alias3'}})
Equivalente con assegnamenti:
t.alias, t.alias1 = t.key, t.key
t.alias2, t.alias3 = t.key1, t.key1
 
--]]
table.tableKeysAlias = function(tab, source, dest)
for destGroup, sourceKey in ipairs(source) do
for _, destKey in ipairs(dest[destGroup]) do
tab[destKey] = tab[sourceKey]
end
end
end
 
return true
table.table_keys_alias, table.keysAlias, table.keys_alias =
table.tableKeysAlias, table.tableKeysAlias, table.tableKeysAlias
t.tableKeysAlias, t.table_keys_alias, t.keysAlias, t.keys_alias =
table.tableKeysAlias, table.tableKeysAlias, table.tableKeysAlias, table.tableKeysAlias
 
--[[
 
Classic fold on lists: applies a binary
function to an accumulator and a value-key
pair taken from the list and returns the
final result. The iterator determines the
order elements are scanned, and therefore
the final result.
 
The function takes the accumulator as the
first argument, then the value and finally
the key; usual key-value order is reversed
because the key is often unnecessary, and
having it last leads to nicer syntax in callers.
 
--]]
table.fold = function(tab, zero, func, iter)
iter = iter or pairs
 
for key, value in iter(tab) do
zero = func(zero, value, key)
end
 
return zero
end
table.eq = table.equal
 
t.foldequal, t.eq = table.foldequal, table.equal
 
--[[
 
Returns a table containing only the elements that satisfy the passed predicate.
Applica una funzione agli elementi di una table
Integer keys are compacted, so that standard library functions will still work:
restituiti dall'iteratore dato, ritornandone un'
in fact, they don't get along well with "holes" in integer keys. Other keys are
altra con i risultati aventi la stessa chiave
kept unchanged.
dell'elemento dato in ingresso alla funzione. Se
non è passato nessun iteratore, si scorrono tutti
gli elementi della table sorgente.
 
The predicate takes as input an element and its key, in this order: in fact,
La funzione riceve in ingresso un elemento e la sua
the key is often unnecessary, and would just clutter the code in these cases.
chiave, in quest'ordine perché la chiave non è sempre
It returns a boolean: if this is true, the element is kept, else is discarded.
necessaria e sarebbe fastidioso avere un argomento
placeholder.
 
--]]
table.mapfilter = function(tab, funct, itercond)
iter = iter or pairs
 
local dest = {}
 
for key, value in iter(tab) do
-- Double loop to keep integer keys sorted and compact
dest[key] = funct(value, key)
for key, value in ipairs(tab) do
if cond(value, key) then
table.insert(dest, value)
end
end
for key, value in table.nonIntPairs(tab) do
if cond(value, key) then
dest[key] = value
end
end
return dest
end
t.filter = table.filter
 
t.map = table.map
 
--[[
iterator defaults to pairs.
 
The function takes as input an element and its kekey, in this order: in fact, the
key is often unnecessary, and would just clutter the code in these cases.
 
return dest
end
 
table.flat_map = table.flatMap
t.flatMap, t.fat_map = table.flatMap, table.flatMap
 
 
--[[
 
Applies a function over all of the elements of a table returned by the passed
Applica una funzione agli elementi di una table
iterator. The function is expected to return a list. The lists produced from
restituiti dall'iteratore dato, ritornandone un'
the elements are converted to numeric lists: the order of the elements is
altra con i risultati aventi chiavi numeriche
determined by the given iterator. These lists are then concatenated together,
nell'ordine proprio dell'iteratore. Se non ne è
in the order the elements of the initial list are returned by the iterator.
passato nessuno, si scorrono tutti gli elementi
della table sorgente.
 
The function takes as input an element and its key, in this order: in fact, the
La funzione riceve in ingresso un elemento e la sua
key is often unnecessary, and would just clutter the code in these cases.
chiave, in quest'ordine perché la chiave non è sempre
necessaria e sarebbe fastidioso avere un argomento
placeholder.
 
--]]
table.mapToNumflatMapToNum = function(tab, funct, iter)
iter = iter or pairs
 
local dest = {}
for keyk, valuev in iter(tab) do
table.insert(destfor _, value in iter(funct(valuev, keyk)) do
table.insert(dest, value)
end
end
return dest
end
table.flat_map_to_num = table.flatMapToNum
t.flatMapToNum, t.flat_map_to_num = table.flatMapToNum, table.flatMapToNum
 
 
table.map_to_num, table.mapToNumeric, table.map_to_numeric
-- Returns the input table, but with keys and values swapped.
= table.mapToNum, table.mapToNum, table.mapToNum
table.flip = function(tab)
t.mapToNum, t.map_to_num, t.mapToNumeric, t.map_to_numeric
local flipped = {}
= table.mapToNum, table.mapToNum, table.mapToNum,
for key, value in pairs(tab) do
table.mapToNum
flipped[value] = key
end
return flipped
end
t.flip = table.flip
 
--[[
 
AppliesRemoves aone function over alllevel of thenesting elements ofin a table-of-tables. returnedReturns bya thenew passedtable.
Non-table elements are left untouched, while subtables are merged in the
iterator. The function is expected to return a list. The lists produced from
returned as they are given by the iterator. The iterator defaults to pairs.
the elements are converted to numeric lists: the order of the elements is
determined by the given iterator. These lists are then concatenated together,
in the order the elements of the initial list are returned by the iterator.
 
As items are processed in the order they are returned by the iterator, care
The function takes as input an element and its ke, in this order: in fact, the
should be taken regarding non-integer indices, since their value are overridden
key is often unnecessary, and would just clutter the code in these cases.
in assignments. For example,
 
table.flatten({{1, 2, key1 = 5}, {key1 = 9}}, ipairs) --> {1, 2, key1 = 9}
table.flatten({{key1 = 9}, {1, 2, key1 = 5}}, ipairs) --> {1, 2, key1 = 5}
 
--]]
table.flatMapToNumflatten = function(tab, funct, iter)
iter = iter or pairs
 
local dest = {}
for k, v in iter(tab) do
forif _, value in iter(functtype(v,) k))== 'table' dothen
dest = table.insertmerge(dest, valuev)
else
dest[k] = v
end
end
return dest
end
t.flatten = table.flatten
 
table.flat_map_to_num, table.flatMapToNumeric, table.flat_map_to_numeric
= table.flatMapToNum, table.flatMapToNum, table.flatMapToNum
t.flatMapToNum, t.flat_map_to_num, t.flatMapToNumeric, t.flat_map_to_numeric
= table.flatMapToNum, table.flatMapToNum, table.flatMapToNum,
table.flatMapToNum
 
--[[
 
Classic fold on lists: applies a binary function to an accumulator and a
Returns true if at least one of the elements in the list satisties a predicate.
value-key pair taken from the list and returns the final result. The iterator
determines the order elements are scanned, and therefore the final result.
 
The predicate function takes the valueaccumulator as the first argument, then the key;value and
finally the key; usual key-value order is reversed because the key is often unnecessary, and
unnecessary, and having it last leads to nicer syntax in the call sitecallers.
 
--]]
table.anyfold = function(tab, functzero, func, iter)
iter = iter or pairs
return table.fold(tab, false,
 
function(acc, value, key)
for key, value in iter(tab) do
return funct(value, key) or acc
endzero = func(zero, value, iterkey)
end
 
return zero
end
t.fold = table.fold
 
t.any = table.any
 
--[[
 
Returns true ifthe allnumber of the elements in thea listtable. satistiesIt ashould predicate.only be used when
Scribunto overrides the # operator so that it doesn't work propertly.
If the second argument is 'num' it only counts items having a integer index,
otherwise it takes all elements in account.
 
--]]
The predicate function takes the value as the first argument, then the key;
table.getn = function(self, count)
usual key-value order is reversed because the key is often unnecessary, and
count = count or 'all'
having it last leads to nicer syntax in the call site.
 
local n = 0
local iterator = (count == true or tostring(count):lower() == 'num')
and ipairs or pairs
 
for _ in iterator(self) do
n = n + 1
end
 
return n
end
t.getn = table.getn
 
 
--[[
 
Returns a numeric table whose elements are the keys of the passed one, in an
unspecified order.
 
--]]
table.allkeys = function(tab, funct, iter)
local keys = {}
return table.fold(tab, true,
for key in functionpairs(acc,tab) value, key)do
return functtable.insert(valuekeys, key) and acc
end, iter)
return keys
end
t.keys = table.keys
 
t.all = table.all
 
--[[
 
Applies a function to the elements of a table scanned by the passed iterator.
Indica se due tables sono uguali, nel più
It returls a table holding the results of the function application, bound to
brutale dei possibili significati: stessi
the same keys as the original items. If no iterator is passed, all elements
elementi associati alle stesse chiavi.
are scanned.
 
The function takes as input an element and its key, in this order: in fact, the
Per comodità, ritorna true anche se gli
key is often unnecessary, and would just clutter the code in these cases.
argomenti non sono tables, purché siano
uguali.
 
--]]
table.equalmap = function(tab1tab, tab2funct, iter)
iter = iter or pairs
 
--[[local dest = {}
for key, value in iter(tab) do
Si confrontano direttamente gli argomenti se
dest[key] = funct(value, key)
uno dei due ha il metamethod __eq o se uno
dei due non è una table
--]]
local mt1 = getmetatable(tab1)
local mt2 = getmetatable(tab2)
if mt1 and mt1.__eq or mt2 and mt2.__eq
or type(tab1) ~= 'table'
or type(tab2) ~= 'table' then
return tab1 == tab2
end
return dest
end
t.map = table.map
 
--[[
Se si hanno due riferimenti alla stessa
table si evitano molte computazioni inutili
--]]
if tab1 == tab2 then
return true
end
 
--[[
Se il numero di elementi è diverso le due
tables non possono essere uguali. Inoltre
gestisce anche il caso in cui tab1 sia vuota
e tab2 no, che porterebbe a tornare true
poiché il loop viene skippato, e quello in
cui tab1 sia un sottoinsieme di tab2 poiché
si controllano solo gli indici della prima.
--]]
if table.getn(tab1) ~= table.getn(tab2) then
return false
end
 
Applies a function to the elements of a table scanned by the passed iterator.
for key, value in pairs(tab1) do
It returls a table holding the results of the function application, bound to
--[[
integer keys in the order the original elements are returned by the iterator.
Stante la type safety di table.equal, è
If no iterator is passed, all elements are scanned.
più comodo fare così
--]]
if not table.equal(value, tab2[key]) then
return false
end
end
 
The function takes as input an element and its key, in this order: in fact, the
return true
key is often unnecessary, and would just clutter the code in these cases.
 
--]]
table.mapToNum = function(tab, funct, iter)
iter = iter or pairs
 
local dest = {}
for key, value in iter(tab) do
table.insert(dest, funct(value, key))
end
return dest
end
table.map_to_num = table.mapToNum
t.mapToNum, t.map_to_num = table.mapToNum, table.mapToNum
 
table.eq = table.equal
t.equal, t.eq = table.equal, table.equal
 
--[[
 
Merges two tables into a new one. Integer indices of the second table will
Ritorna una table risultato della fusione delle
follow the ones of the first; other indices overwrite the ones of the first
due passate. Gli indici numerici della seconda
in case of equlity.
seguiranno quelli della prima; gli altri sono
lasciati invariati, ed in caso di uguaglianza
quelli della seconda sovrascrivono i valori della
prima.
 
--]]
table.merge = function(tab1, tab2)
-- Better to use mw.clone, so as to keep metatable of items.
 
local dest = mw.clone(tab1)
 
-- Double loop to keep integer keys sorted
--[[
È necessario il doppio ciclo per avere
le chiavi intere in ordine
--]]
for _, value in ipairs(tab2) do
table.insert(dest, value)
return dest
end
 
t.merge = table.merge
 
--[[
 
-- Stateless iterator to be used in for loops
Ritorna una table risultato della fusione delle
table.nonIntPairs = function(tab)
due passate. Gli indici numerici della seconda
return nextNonInt, tab
seguiranno quelli della prima; gli altri sono
end
lasciati invariati, ed in caso di uguaglianza
table.non_int_pairs = t.nonIntPairs
quelli della seconda sovrascrivono i valori della
t.nonIntPairs, t.non_int_pairs = table.nonIntPairs, table.nonIntPairs
prima. Fanno però eccezione le tables, che sono
fuse a loro volta.
 
--]]
table.recursiveMerge = function(tab1, tab2)
 
-- Linear search. Returns the index of the passed value if found, else nil.
local dest = mw.clone(tab1)
table.search = function(tab, value)
--[[
for k, v in pairs(tab) do
È necessario il doppio ciclo per avere
leif chiaviv intere== invalue ordinethen
return k
--]]
for _, value in ipairs(tab2) do
table.insert(dest, value)
end
for key, value in table.nonIntPairs(tab2) do
if dest[key]
and type(dest[key]) == 'table'
and type(value) == 'table'
then
dest[key] = table.recursiveMerge(dest[key], value)
else
dest[key] = value
end
end
-- No explicit return, thus destnil
end
t.search = table.search
 
table.recursive_merge = table.recursiveMerge
t.recursive_merge, t.recursive_merge =
table.recursiveMerge, table.recursiveMerge
 
--[[
 
Returns the elements of a numeric table whose indices are within the specified
Ritorna una table con i soli elementi che
range. The end of the range defaults to the end of the source table.
rispettano la condizione passata. Tale
funzione deve quindi ritornare un booleano,
avendo in ingresso un elemento e la sua
chiave, in quest'ordine perché la chiave
non è sempre necessaria e sarebbe fastidioso
avere un argomento placeholder.
 
Negative values count from the end of the table. For example, -1 is the last
Le chiavi rimangono invariate con la sola
element, -2 is the second last and so on.
eccezione di quelle numeriche, che sono
rese continue
 
--]]
table.filterslice = function(tab, condfrom, to)
local destlength = {}#tab
 
--[[
to = to or length
È necessario il doppio ciclo per avere
if from < 0 then
le chiavi intere in ordine
from = length + from + 1 -- + because from is negative
--]]
for key, value in ipairs(tab) do
if cond(value, key) then
table.insert(dest, value)
end
end
if to < 0 then
for key, value in table.nonIntPairs(tab) do
to = length + to + 1 -- + because to is negative
if cond(value, key) then
end
dest[key] = value
 
end
local dest = {}
for k = from, to do
table.insert(dest, tab[k])
end
return dest
end
t.slice = table.slice
 
t.filter = table.filter
 
--[[
 
Aliases keys in a single table. Arguments:
Ritorna una table con chiavi e valori
- tab: the source table
invertiti rispetto a quella passata.
- source: list of keys to be aliased
- dest: list of tables, in which every element contains the aliases
to its corresponding one in source.
 
Example:
table.tableKeysAlias(t, {'key', 'key1'}, {{'alias', alias1'},
{'alias2', 'alias3'}})
Equivalent with assignments:
t.alias, t.alias1 = t.key, t.key
t.alias2, t.alias3 = t.key1, t.key1
 
--]]
table.fliptableKeysAlias = function(tab, source, dest)
for destGroup, sourceKey in ipairs(source) do
local flipped = {}
for key_, valuedestKey in pairsipairs(tabdest[destGroup]) do
flipped tab[valuedestKey] = keytab[sourceKey]
end
end
return flipped
end
 
table.table_keys_alias, table.keysAlias, table.keys_alias =
t.flip = table.flip
table.tableKeysAlias, table.tableKeysAlias, table.tableKeysAlias
t.tableKeysAlias, t.table_keys_alias, t.keysAlias, t.keys_alias =
table.tableKeysAlias, table.tableKeysAlias, table.tableKeysAlias, table.tableKeysAlias
 
--[[
 
--[[
Ritorna una table con gli stessi elementi di
quella passata, ma senza duplicati.
 
Returns a table with the same items of the input one, but without duplicates.
Le chiavi degli elementi mantenuti sono le
The keys of repeated elements that are kept are the first in lexicographic
prime in ordine lessicografico rispetto alle
order, unless they are integer: in this case they are compacted to allow
chiavi dei grupppi di elementi uguali, con
compatibility with standard library functions.
la sola eccezione di quelle intere che sono
rese contigue.
 
--]]
table.noDuplicatesunique = function(tab)
local check, n = {}, 1
 
--[[
Check is meant to be used to test uniqueness of values: the most
Il doppio ciclo si rende necessario per
efficient implementation is to keep values as indices, so that
mantenere l'ordine delle chiavi numeriche.
uniqueness can be checked with simple table indexing. The values are
La variabile n serve per non avere buchi.
the indices in the final table, so that they can easily be flipped.
Non si usa minor poiché le chiavi vengono
 
già tornate in ordine crescente da ipairs.
n is used as incremental integer index, to avoid "holes" in the final
table.
--]]
local check, n = {}, 1
 
-- Minor is not used as ipairs returns integer keys in ascending order.
for _, value in ipairs(tab) do
if not check[value] then
 
for key, value in table.nonIntPairs(tab) do
--[[
If value is not in check, minor returns true, as the second
argument is nil
--]]
if minor(key, check[value]) then
check[value] = key
return table.flip(check)
end
t.unique = table.unique
 
table.no_duplicates, table.unique =
table.noDuplicates, table.noDuplicates
t.noDuplicates, t.no_duplicates, t.unique =
table.noDuplicates, table.noDuplicates, table.noDuplicates
 
--[[
 
Ritorna una table con soli indici numerici
i cui elementi sono le chiavi della table
passata, in ordine non specificato
 
--]]
table.keys = function(tab)
local keys = {}
for key in pairs(tab) do
table.insert(keys, key)
end
return keys
end
 
t.keys = table.keys
 
--[[
 
Returns a numeric table containing the values of the passed table, in the
order they are returned in by the iterator. Such iterator defaults to pairs,.
and should return two values, the first being the key and the second the value.
 
--]]
return values
end
 
t.values = table.values
 
--[[
 
Returns a table from two sources. The items of the new table are obtained by
Given a table with numeric indexes,
combining the elements with the same index in the two sources. The default
returns another table containing its
combinator creates a pair, as a table with two elements.
elements in the specified indexes
 
range. End index defaults to largest
The used indices are those of the first table returned by the iterator. No
index in the table.
other indices will be considered, especially the extra indices of the second
table. The iterator defaults to pairs.
 
--]]
table.slicezip = function(tabtab1, fromtab2, tocombinator, iter)
combinator = combinator or function(a, b) return {a, b} end
to = to or #tab
iter = iter or pairs
return table.filter(tab, function(_, key)
return key >= from and key <= to
end, ipairs)
end
 
local res = {}
t.slice = table.slice
for k, v in iter(tab1) do
 
res[k] = combinator(v, tab2[k])
--[[
 
Ritorna una copia di una table di un modulo
caricato con mw.loadData. La table ritornata,
essendo una copia, non è read-only, ed è quindi
possibile usare su di essa la table library
 
--]]
table.copy = function(value)
local dest = {}
for k, v in pairs(value) do
dest[k] = type(v) == 'table'
and table.copy(v)
or v
end
return destres
end
t.zip = table.zip
 
t.copy = table.copy
table.cloneLoadData, table.clone_load_data =
table.copy, table.copy
t.cloneLoadData, t.clone_load_data =
table.copy, table.copy
 
return t
106 665

contributi

Menu di navigazione