From b2c3f581ec2ca673959ce0c7ff374ff47ac73405 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 13 Nov 2020 16:52:43 +0000 Subject: [PATCH] [Minor] Selectors: filter_string_nils utility transformation --- lualib/lua_selectors/transforms.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua index 1a27b775d..232a49b79 100644 --- a/lualib/lua_selectors/transforms.lua +++ b/lualib/lua_selectors/transforms.lua @@ -458,6 +458,17 @@ Empty string comes the first argument or 'true', non-empty string comes nil]], ['description'] = 'Converts a list of strings to numbers & returns a packed string', ['args_schema'] = {ts.string:is_optional()} }, + -- Filter nils from a list + ['filter_string_nils'] = { + ['types'] = { + ['string_list'] = true + }, + ['process'] = function(inp, _, _) + return fun.filter(function(val) return type(val) == 'string' and val ~= 'nil' end, inp), 'string_list' + end, + ['description'] = 'Removes all nils from a list of strings (when converted implicitly)', + ['args_schema'] = {} + }, } transform_function.match = transform_function.regexp -- 2.39.5