]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_util: Add `flatten` function
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Jul 2019 16:51:00 +0000 (17:51 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Jul 2019 16:51:00 +0000 (17:51 +0100)
lualib/lua_util.lua

index 432f55c6aae0be38c7022f478bd33439f11a3348..b8420c7a4ff37f7c456cba4730b7be768671d856 100644 (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