浏览代码

[Minor] Lua_util: Add `flatten` function

tags/2.0
Vsevolod Stakhov 5 年前
父节点
当前提交
01329335b7
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17
    0
      lualib/lua_util.lua

+ 17
- 0
lualib/lua_util.lua 查看文件

@@ -284,6 +284,23 @@ exports.unpack = function(t)
return unpack_function(t)
end

--[[[
-- @function lua_util.flatten(table)
-- Flatten underlying tables in a single table
-- @param {table} table table of tables
-- @return {table} flattened table
--]]
exports.flatten = function(t)
local res = {}
for _,e in fun.iter(t) do
for _,v in fun.iter(e) do
res[#res + 1] = v
end
end

return res
end

--[[[
-- @function lua_util.spairs(table)
-- Like `pairs` but keys are sorted lexicographically

正在加载...
取消
保存