]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add take_n/drop_n processing functions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 13 Sep 2018 14:26:42 +0000 (15:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 13 Sep 2018 14:26:42 +0000 (15:26 +0100)
lualib/lua_selectors.lua

index 66f2906d1886db90520ff0dd7dd201bc6b37970b..cef2d163f54c1c32b864d832232e1f904fe44b4b 100644 (file)
@@ -329,6 +329,24 @@ local transform_function = {
     end,
     ['description'] = 'Returns the nth element',
   },
+  ['take_n'] = {
+    ['types'] = {
+      ['list'] = true,
+    },
+    ['process'] = function(inp, t, args)
+      return fun.take_n(tonumber(args[1]) or 1, inp),t
+    end,
+    ['description'] = 'Returns the n first elements',
+  },
+  ['drop_n'] = {
+    ['types'] = {
+      ['list'] = true,
+    },
+    ['process'] = function(inp, t, args)
+      return fun.drop_n(tonumber(args[1]) or 1, inp),t
+    end,
+    ['description'] = 'Returns list without the first n elements',
+  },
   -- Joins strings into a single string using separator in the argument
   ['join'] = {
     ['types'] = {