class PipelineFunctionFilter implements PipelineFunction {

    @Override
    public PipelineElement apply(final PipelineElement value, final String paramsIncludingParentheses,
            final ExpressionResolver expressionResolver) {

        final Map<String, String> parameters = parseAndResolve(paramsIncludingParentheses, expressionResolver);

        return value.onResolved(valueThatShouldBeFilteredConditionally -> {

            final Optional<FilterFunction> rqlFunctionOpt =
                    FilterFunctions.fromName(parameters.get(RqlFunctionParam.NAME));
            final boolean shouldKeepValue = rqlFunctionOpt.map(rqlFunction -> {
                final String filterValue = parameters.get(FilterValueParam.NAME);
                final String comparedValue = parameters.get(ComparedValueParam.NAME);
                return rqlFunction.apply(filterValue, comparedValue);
            }).orElse(false);


            if (shouldKeepValue) {
                return PipelineElement.resolved(valueThatShouldBeFilteredConditionally);
            } else {
                return PipelineElement.unresolved();
            }

        });
    }

}