Browse Source

[Minor] Selectors: Add except_map function

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
0c8dcea94a
1 changed files with 25 additions and 0 deletions
  1. 25
    0
      lualib/lua_selectors/transforms.lua

+ 25
- 0
lualib/lua_selectors/transforms.lua View File

['description'] = 'Returns a value if it exists in some map (or acts like a `filter` function)', ['description'] = 'Returns a value if it exists in some map (or acts like a `filter` function)',
['args_schema'] = {ts.string} ['args_schema'] = {ts.string}
}, },
-- Returns a value if it exists in some map (or acts like a `filter` function)
['except_map'] = {
['types'] = {
['string'] = true
},
['map_type'] = 'string',
['process'] = function(inp, t, args)
local map = maps[args[1]]

if not map then
logger.errx('invalid map name: %s', args[1])
return nil
end

local res = map:get_key(inp)

if not res then
return inp,t
end

return nil
end,
['description'] = 'Returns a value if it does not exists in some map (or acts like a `except` function)',
['args_schema'] = {ts.string}
},
-- Returns a value from some map corresponding to some key (or acts like a `map` function) -- Returns a value from some map corresponding to some key (or acts like a `map` function)
['apply_map'] = { ['apply_map'] = {
['types'] = { ['types'] = {

Loading…
Cancel
Save