Browse Source

[Minor] Lua_util: Add `flatten` function

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
01329335b7
1 changed files with 17 additions and 0 deletions
  1. 17
    0
      lualib/lua_util.lua

+ 17
- 0
lualib/lua_util.lua View File

@@ -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

Loading…
Cancel
Save