Eager comprehensions
A comprehension puts the produced value first, followed by one or more for clauses and optional if guards. Square brackets build an array; braces build a dictionary.
Clauses nest from left to right. Later equal dictionary keys replace the value without moving the key's original position.
fn main() {
let squares = [x * x for x in 0..6 if x % 2 == 0]
let parity = {x % 2: x for x in 0..5}
println(squares)
println(parity)
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected:
[0, 4, 16]
{0: 4, 1: 3}
Ctrl/⌘+Enter runs the current lesson.