No Operation Expression for Filter Pattern

Sometimes, it is necessary to conditionally build a filter. To avoid writing complex code that calls different methods on PipelineStage depending on whether a filter needs to be added, users can use a no-operation (noop) expression. This approach simplifies the code and improves readability.

Code

Groovy
protected Expression buildQueryExpression(Table table, String customerType, Integer revenueTotal) {
    Exprs exprs = api.queryApi().exprs()

    List<Expression> expressions = []

    if (customerType) {
        expressions += table.getAt("CustomerType").equal(customerType)
    }

    if (revenueTotal) {
        expressions += table.getAt("Revenue").lessThan(revenueTotal)
    }

    return expressions ? exprs.and(*expressions) : exprs.bool(true)