aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-24 13:07:51 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-24 13:07:51 +0100
commit7a0b99449428fc397d7c9f7d28cb1de34c3ecee7 (patch)
treefff3356e6909be449ac4f7dff36fd43a7b6ec37c /lualib
parentff7352bec19a5044b577d5b315209ad101ea0bcb (diff)
downloadrspamd-7a0b99449428fc397d7c9f7d28cb1de34c3ecee7.tar.gz
rspamd-7a0b99449428fc397d7c9f7d28cb1de34c3ecee7.zip
[Feature] Lua_selectors: Add sort and uniq transform functions
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_selectors.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua
index b678ef179..15777fc11 100644
--- a/lualib/lua_selectors.lua
+++ b/lualib/lua_selectors.lua
@@ -423,6 +423,32 @@ local transform_function = {
['description'] = 'Joins strings into a single string using separator in the argument',
['args_schema'] = {ts.string:is_optional()}
},
+ -- Sort strings
+ ['sort'] = {
+ ['types'] = {
+ ['list'] = true
+ },
+ ['process'] = function(inp, t, _)
+ table.sort(inp)
+ return inp, t
+ end,
+ ['description'] = 'Sort strings lexicographically',
+ },
+ -- Return unique elements based on hashing (can work without sorting)
+ ['uniq'] = {
+ ['types'] = {
+ ['list'] = true
+ },
+ ['process'] = function(inp, t, _)
+ local tmp = {}
+ for _,val in ipairs(inp) do
+ tmp[val] = true
+ end
+
+ return fun.map(function(k, _) return k end, tmp), t
+ end,
+ ['description'] = 'Returns a list of unique elements (using a hash table)',
+ },
-- Create a digest from string or a list of strings
['digest'] = {
['types'] = {