| 🌟 | 現在、 鉄壁HSは通常HSと同じダメージになります。LMG及びDMR、チャージライフル、ハンマーポイント弾を除き、すべてのダメージ値が一致していることを確認しています。 |
「モジュール:TableExtensions」の版間の差分
ナビゲーションに移動
検索に移動
(関数 mapKeys の追加) |
(型チェックの追加) |
||
| 1行目: | 1行目: | ||
function table.isEmpty(tbl) | function table.isEmpty(tbl) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
return not next(tbl) | return not next(tbl) | ||
end | end | ||
function table.keys(tbl) | function table.keys(tbl) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
local keyset = {} | local keyset = {} | ||
for key, _ in pairs(tbl) do | for key, _ in pairs(tbl) do | ||
| 12行目: | 16行目: | ||
function table.values(tbl) | function table.values(tbl) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
local valueset = {} | local valueset = {} | ||
for _, value in pairs(tbl) do | for _, value in pairs(tbl) do | ||
| 20行目: | 26行目: | ||
function table.entries(tbl) | function table.entries(tbl) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
local entryset = {} | local entryset = {} | ||
for key, value in pairs(tbl) do | for key, value in pairs(tbl) do | ||
| 28行目: | 36行目: | ||
function table.map(tbl, fn) | function table.map(tbl, fn) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
assert(type(fn) == 'function', debug.traceback()) | |||
local ret = {} | local ret = {} | ||
for key, value in pairs(tbl) do | for key, value in pairs(tbl) do | ||
| 36行目: | 47行目: | ||
function table.mapKeys(tbl, fn) | function table.mapKeys(tbl, fn) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
assert(type(fn) == 'function', debug.traceback()) | |||
local ret = {} | local ret = {} | ||
for key, value in pairs(tbl) do | for key, value in pairs(tbl) do | ||
| 44行目: | 58行目: | ||
function table.mapValues(tbl, fn) | function table.mapValues(tbl, fn) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
assert(type(fn) == 'function', debug.traceback()) | |||
local ret = {} | local ret = {} | ||
for key, value in pairs(tbl) do | for key, value in pairs(tbl) do | ||
| 52行目: | 69行目: | ||
function table.filter(tbl, fn) | function table.filter(tbl, fn) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
assert(type(fn) == 'function', debug.traceback()) | |||
local ret = {} | local ret = {} | ||
for idx, value in ipairs(tbl) do | for idx, value in ipairs(tbl) do | ||
| 67行目: | 87行目: | ||
function table.removeKey(tbl, key) | function table.removeKey(tbl, key) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
local element = tbl[key] | local element = tbl[key] | ||
tbl[key] = nil | tbl[key] = nil | ||
| 73行目: | 95行目: | ||
function table.reverse(tbl) | function table.reverse(tbl) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
local n = #tbl | local n = #tbl | ||
local i = 1 | local i = 1 | ||
| 83行目: | 107行目: | ||
function table.reversed(tbl) | function table.reversed(tbl) | ||
assert(type(tbl) == 'table', debug.traceback()) | |||
local ret = {} | local ret = {} | ||
for i = #tbl, 1, -1 do | for i = #tbl, 1, -1 do | ||
2022年6月13日 (月) 10:41時点における最新版
このモジュールについての説明文ページを モジュール:TableExtensions/doc に作成できます
function table.isEmpty(tbl)
assert(type(tbl) == 'table', debug.traceback())
return not next(tbl)
end
function table.keys(tbl)
assert(type(tbl) == 'table', debug.traceback())
local keyset = {}
for key, _ in pairs(tbl) do
keyset[#keyset + 1] = key
end
return keyset
end
function table.values(tbl)
assert(type(tbl) == 'table', debug.traceback())
local valueset = {}
for _, value in pairs(tbl) do
valueset[#valueset + 1] = value
end
return valueset
end
function table.entries(tbl)
assert(type(tbl) == 'table', debug.traceback())
local entryset = {}
for key, value in pairs(tbl) do
entryset[#entryset + 1] = { key, value }
end
return entryset
end
function table.map(tbl, fn)
assert(type(tbl) == 'table', debug.traceback())
assert(type(fn) == 'function', debug.traceback())
local ret = {}
for key, value in pairs(tbl) do
ret[key] = fn(key, value)
end
return ret
end
function table.mapKeys(tbl, fn)
assert(type(tbl) == 'table', debug.traceback())
assert(type(fn) == 'function', debug.traceback())
local ret = {}
for key, value in pairs(tbl) do
ret[fn(key)] = value
end
return ret
end
function table.mapValues(tbl, fn)
assert(type(tbl) == 'table', debug.traceback())
assert(type(fn) == 'function', debug.traceback())
local ret = {}
for key, value in pairs(tbl) do
ret[key] = fn(value)
end
return ret
end
function table.filter(tbl, fn)
assert(type(tbl) == 'table', debug.traceback())
assert(type(fn) == 'function', debug.traceback())
local ret = {}
for idx, value in ipairs(tbl) do
if fn(idx, value) then
ret[#ret + 1] = value
end
end
for key, value in pairs(tbl) do
if type(key) ~= 'number' and fn(key, value) then
ret[key] = value
end
end
return ret
end
function table.removeKey(tbl, key)
assert(type(tbl) == 'table', debug.traceback())
local element = tbl[key]
tbl[key] = nil
return element
end
function table.reverse(tbl)
assert(type(tbl) == 'table', debug.traceback())
local n = #tbl
local i = 1
while i < n do
tbl[i], tbl[n] = tbl[n], tbl[i]
i = i + 1
n = n - 1
end
end
function table.reversed(tbl)
assert(type(tbl) == 'table', debug.traceback())
local ret = {}
for i = #tbl, 1, -1 do
ret[#ret + 1] = tbl[i]
end
return ret
end
return table