From aa95595931bf1ad08c1ee20f144074e31222acd8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 21 Aug 2018 12:39:33 +0100 Subject: [PATCH] [Minor] Add `in` and `not_in` transformations --- lualib/lua_selectors.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua index 69a20b9c4..5f2f3564a 100644 --- a/lualib/lua_selectors.lua +++ b/lualib/lua_selectors.lua @@ -382,6 +382,27 @@ local transform_function = { return inp[args[1]](inp) end }, + -- Boolean function in, returns either nil or its input if input is in args list + ['in'] = { + ['types'] = { + ['string'] = true, + }, + ['map_type'] = 'string', + ['process'] = function(inp, _, args) + for _,a in ipairs(args) do if a == inp then return inp end end + return nil + end + }, + ['not_in'] = { + ['types'] = { + ['string'] = true, + }, + ['map_type'] = 'string', + ['process'] = function(inp, _, args) + for _,a in ipairs(args) do if a == inp then return nil end end + return inp + end + }, } local function process_selector(task, sel) -- 2.39.5