Browse Source

[Minor] Selectors: Filter empty values when doing map

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
9a9b633f5a
1 changed files with 21 additions and 14 deletions
  1. 21
    14
      lualib/lua_selectors.lua

+ 21
- 14
lualib/lua_selectors.lua View File

@@ -723,10 +723,12 @@ local function process_selector(task, sel)
if meth.types[pt] then
lua_util.debugm(M, task, 'map method `%s` to list of %s',
meth.name, pt)
input = fun.map(function(list_elt)
local ret, _ = meth.process(list_elt, pt)
return ret
end, input)
-- Map method to a list of inputs, excluding empty elements
input = fun.filter(function(map_elt) return map_elt end,
fun.map(function(list_elt)
local ret, _ = meth.process(list_elt, pt)
return ret
end, input))
etype = 'string_list'
end
end
@@ -743,10 +745,11 @@ local function process_selector(task, sel)
etype = 'string'
else
lua_util.debugm(M, task, 'apply implicit map %s->string', pt)
input = fun.map(function(list_elt)
local ret = implicit_tostring(pt, list_elt)
return ret
end, input)
input = fun.filter(function(map_elt) return map_elt end,
fun.map(function(list_elt)
local ret = implicit_tostring(pt, list_elt)
return ret
end, input))
etype = 'string_list'
end
end
@@ -773,12 +776,16 @@ local function process_selector(task, sel)
local map_type = x.map_type .. '_list'
lua_util.debugm(M, task, 'map `%s` to list of %s resulting %s',
x.name, pt, map_type)

return {fun.map(function(list_elt)
if not list_elt then return nil end
local ret, _ = x.process(list_elt, pt, x.args)
return ret
end, value), map_type}
-- Apply map, filtering empty values
return {
fun.filter(function(map_elt) return map_elt end,
fun.map(function(list_elt)
if not list_elt then return nil end
local ret, _ = x.process(list_elt, pt, x.args)
return ret
end, value)),
map_type -- Returned type
}
end
logger.errx(task, 'cannot apply transform %s for type %s', x.name, t)
return nil

Loading…
Cancel
Save