Skip to content

Commit

Permalink
[Minor] Selectors: Filter empty values when doing map
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Jul 19, 2019
1 parent b71ee0b commit 9a9b633
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lualib/lua_selectors.lua
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9a9b633

Please sign in to comment.