Product SiteDocumentation Site

5.4.3. Sequence predicates

Predicate
Figure 5.31. 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.
ContextItemExpr
Figure 5.32. ContextItemExpr

If the predicate evaluates to an integer, it is matched against the item position in the left-hand side sequence automatically
Example 5.82. 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 5.83. Predicate expression
(1 to 10)[$$ mod 2 eq 0]
Result (run with Zorba):
2 4 6 8 10