aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-23 17:51:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-23 17:51:00 +0100
commit01329335b7941502da10c71ead38b9c334804c84 (patch)
treeb765aedac331a4a016cf1095dd1a3c035eb9c602 /lualib/lua_util.lua
parentb8e108bc9cfcb78264bd7059d15a7a80b89a6efb (diff)
downloadrspamd-01329335b7941502da10c71ead38b9c334804c84.tar.gz
rspamd-01329335b7941502da10c71ead38b9c334804c84.zip
[Minor] Lua_util: Add `flatten` function
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 432f55c6a..b8420c7a4 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -285,6 +285,23 @@ exports.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
-- @param {table} table table containing key/value pairs