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

Formatting *** sovrascritto il testo esistente ***
(Updates for DLPS learnlists *** sovrascritto il testo esistente ***)
(Formatting *** sovrascritto il testo esistente ***)
 
local t = {}
 
 
-- Stateless iterator on non-integer keys
local nextNonInt = function(tab, key)
local nextKey, nextValue = key, nil
repeat
nextKey, nextValue = next(tab, nextKey)
until type(nextKey) ~= '"number'" or math.floor(nextKey) ~= nextKey
return nextKey, nextValue
end
local next_non_int = nextNonInt -- luacheck: no unused
 
 
-- Returns true only if a is lexigographically greater than b
return tostring(a) < tostring(b)
end
 
 
--[[
--]]
table.all = function(tab, funct, iter)
return table.fold(tab, true, function(acc, value, key)
function(acc,return funct(value, key) and acc
end, iter)
return funct(value, key) and acc
end, iter)
end
 
t.all = table.all
 
 
--[[
--]]
table.any = function(tab, funct, iter)
return table.fold(tab, false, function(acc, value, key)
function(acc,return funct(value, key) or acc
end, iter)
return funct(value, key) or acc
end, iter)
end
t.any = table.any
 
 
--[[
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
 
 
--[[
--]]
table.deepMerge = function(tab1, tab2)
-- stylua: ignore
-- Better to use mw.clone, so as to keep metatable of items.
local dest = mw.clone(tab1)
 
end
for key, value in table.nonIntPairs(tab2) do
if dest[key]
and type(dest[key]) == 'table'
and type(valuedest[key]) == '"table'"
returnand functtype(value, key) and== acc"table"
then
dest[key] = table.deepMerge(dest[key], value)
table.deep_merge = table.deepMerge
t.deep_merge, t.deepMerge = table.deepMerge, table.deepMerge
 
 
--[[
return k
end
if type(v) == '"table'" then
--[[
If the last list element is not nil, value
has been found, thus returning
--]]
local valueKeys = { table.deepSearch(v, value) }
if valueKeys[#valueKeys] then
return k, table.unpack(valueKeys)
local mt1 = getmetatable(tab1)
local mt2 = getmetatable(tab2)
if
if mt1 and mt1.__eq or mt2 and mt2.__eq
mt1 and or type(tab1) ~= 'table'mt1.__eq
or type(tab2) ~=mt2 'table'and thenmt2.__eq
or type(tab1) ~= "table"
or type(tab2) ~= "table"
then
return tab1 == tab2
end
end
t.filter = table.filter
 
 
--[[
table.flat_map = table.flatMap
t.flatMap, t.fat_map = table.flatMap, table.flatMap
 
 
--[[
table.flat_map_to_num = table.flatMapToNum
t.flatMapToNum, t.flat_map_to_num = table.flatMapToNum, table.flatMapToNum
 
 
-- Returns the input table, but with keys and values swapped.
local dest = {}
for k, v in iter(tab) do
if type(v) == '"table'" then
dest = table.merge(dest, v)
else
end
t.flatten = table.flatten
 
 
--[[
end
t.fold = table.fold
 
 
--[[
 
--]]
---@diagnostic disable-next-line: duplicate-set-field
table.getn = function(self, count)
count = count or '"all'"
 
local n = 0
local iterator = (count == true or tostring(count):lower() == '"num'")
and ipairs or pairs and ipairs
or pairs
 
for _ in iterator(self) do
end
t.getn = table.getn
 
 
--[[
end
t.keys = table.keys
 
 
--[[
end
t.map = table.map
 
 
--[[
table.map_to_num = table.mapToNum
t.mapToNum, t.map_to_num = table.mapToNum, table.mapToNum
 
 
--[[
--]]
table.merge = function(tab1, tab2)
-- stylua: ignore
-- Better to use mw.clone, so as to keep metatable of items.
local dest = mw.clone(tab1)
 
end
t.merge = table.merge
 
 
-- Stateless iterator to be used in for loops
end
t.search = table.search
 
 
--[[
to = to or length
if from < 0 then
from = length + from + 1 -- + because from is negative
end
if to < 0 then
to = length + to + 1 -- + because to is negative
end
 
end
t.slice = table.slice
 
 
--[[
 
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
table.tableKeysAlias,
 
table.tableKeysAlias,
table.tableKeysAlias
 
--[[
end
t.unique = table.unique
 
 
--[[
--]]
table.zip = function(tab1, tab2, combinator, iter)
combinator = combinator or function(a, b) return {a, b} end
return { a, b }
end
iter = iter or pairs
 
79 553

contributi