Starting with version 1.23, support for iterators has been added, which lets us range over pretty much anything!
Let’s look at the List type from the previous example again. In that example, we had an AllElements method that returned a slice of all elements in the list. With iterators, we can do it better - as shown below.
In this translation, concepts like iterators are implemented using C++ functions and lambdas. The All method returns a lambda function that iterates over the elements in the list and calls the yield function for each element. The genFib function generates Fibonacci numbers and uses a similar lambda-based approach for iteration.