Search code examples
filtersequencefreemarker

how to create a new filtered sequence from another


If I have a sequence like:

<#assign seq = ['a', 'b', 'c', 'd', 'e']>

I'd need to obtain some new sequences that are filtered versions of the original one. For example:

<#assign seq1 = ['a', 'b']>
<#assign seq2 = ['b', 'd', 'e']>

I thought about the filter built-in but how to add more than one condition? For example, something like:

seq?filter(x -> (x == 'a' OR x == 'b'))

...


Solution

  • Like seq?filter(x -> x == 'a' || x == 'b'). The part after the -> is just any expression that evaluates to a boolean value, so of course it can use ||, &&, call functions, etc.