Product SiteDocumentation Site

7.3. Sequence Filtering

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. The predicate expression can use $$ to refer to the item being processed, called the context item.
If the predicate evaluates to an integer, it is matched against the item position in the left-hand side sequence automatically.
Example 7.9. Predicate expression for picking an item at a given position.
(1 to 10)[5],
(
  "What NoSQL technology should I use?",
  "What is the bottleneck in MapReduce?"
)[2]
Results:
5
"What is the bottleneck in MapReduce?"

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 7.10. Predicate expression for filtering.
(
  "What NoSQL technology should I use?",
  "What is the bottleneck in MapReduce?"
)[contains($$, "NoSQL")],

(1 to 10)[$$ mod 2 eq 0]
Results:
"What NoSQL technology should I use?"
2
4
6
8
10