Array Comprehensions¶
Array comprehensions build a new array from an existing collection in a single expression.
When to use it¶
Use a comprehension when you only need a simple mapping or filtering expression and want a concise result.
Syntax¶
LET squares = [FOR (n IN input.numbers) => n * n];
LET evens = [FOR (n IN input.numbers) IF n % 2 == 0 => n];
Example¶
Pitfalls¶
- Comprehensions allow only a single expression after
=>. - Use
FOR EACHif you need multiple statements or side effects.
Try it¶
Open collection-transforms to see comprehensions alongside MAP/FILTER/REDUCE.