Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Lazy and infinite sequences / Infinite sequences
Quiz — Lazy sequences
What does the following program print?
say (2, 4, 6 ... *)[5];| 0 | 10 |
| 1 | 12 |
| 0 | 14 |
| 0 | 6 |
(2, 4, 6 ... *) is the infinite sequence of even
numbers. Counting from index zero, element 5 is the sixth
even number, 12. Only as many elements as needed are
computed, thanks to laziness.