Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming

Iterators

An iterator produces a series of values one at a time, on demand. Raku gives you a beautifully simple way to write your own: the gather / take pair. Inside a gather block, every take contributes a value to the resulting list.

Because the values are produced lazily — only as they are pulled — gather can even describe an endless series. This section shows how to build sequences with gather and take.

Topics in this section

Practice

Complete the quiz that covers the contents of this section.

Exercises

This section contains 3 exercises. Examine all the topics of this section before doing the coding practice.

  1. Gather the cubes
  2. Gather the multiples of three
  3. Gather with a condition

Course navigation

Solution: Sort with a feed   |   gather and take