Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Iterators / The iterator protocol

Quiz — The iterator protocol

When an iterator has no more values to give, what does pull-one return, and how do you test for it?

1IterationEnd, tested with =:=
0Nil, tested with .defined
0an empty list (), tested with ==
00, tested with =:=

An exhausted iterator returns the sentinel object IterationEnd. Because it is a single shared object, you check for it by identity with =:= (the same object test), not by value or definedness. A for loop uses exactly this check to know when to stop.

Course navigation

The iterator protocol   |   Writing an iterator