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 = [n * n FOR EACH n IN input.numbers]
LET evens = [n FOR EACH n IN input.numbers WHERE n % 2 == 0]
Example¶
Pitfalls¶
- Comprehensions allow only a single result expression before
FOR EACH. - Use
FOR EACHif you need multiple statements or side effects.
Try it¶
Open collection-transforms to see comprehensions alongside MAP/FILTER/REDUCE.