Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Lazy and infinite sequences / Exercises / The first multiples of seven

Solution: The first multiples of seven

Here is a possible solution to the task.

Code

say (1..*).map(* * 7).head(5);

🦋 You can find the source code in the file first-squares.raku.

Output

(7 14 21 28 35)

Comments

  1. 1..* is an infinite range; .map(* * 7) multiplies each element by seven lazily.

  2. .head(5) pulls only the first five, so the infinite source is never fully computed.

Course navigation

The first multiples of seven   |   Powers of three