Skip to content

Commit

Permalink
[Minor] Add selector transformer filter_method
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Oct 31, 2023
1 parent bfa0976 commit 3a3c66d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lualib/lua_selectors/transforms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,28 @@ Empty string comes the first argument or 'true', non-empty string comes nil]],
return res, 'string_list'
end,
['description'] = 'Apply a list of method calls to the userdata object',
}
},
-- Apply method to list of userdata and use it as a filter, excluding elements for which method returns false/nil
['filter_method'] = {
['types'] = {
['userdata_list'] = true
},
['process'] = function(inp, t, args)
local meth = args[1]

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

return fun.filter(function(val)
return val[meth](val)
end, inp), 'userdata_list'
end,
['description'] = 'Apply method to list of userdata and use it as a filter,' ..
' excluding elements for which method returns false/nil',
['args_schema'] = { ts.string }
},
}

transform_function.match = transform_function.regexp
Expand Down

0 comments on commit 3a3c66d

Please sign in to comment.