Figure 47. Predicate
A predicate allows filtering a sequence, keeping only items that fulfill it.
The predicate is evaluated once for each item in the left-hand-side sequence, with the context item set to that item. The predicate expression can use $$ to access this context item.
Figure 48. ContextItemExpr
If the predicate evaluates to an integer, it is matched against the item position in the left-hand side sequence automatically
Example 95. Predicate expression
(1 to 10)[2]
Result (run with Zorba): 2
Otherwise, the result of the predicate is converted to a boolean.
All items for which the converted predicate result evaluates to true are then output.
Example 96. Predicate expression
(1 to 10)[$$ mod 2 eq 0]
Result (run with Zorba): 2 4 6 8 10