Starting with version 1.23, support has been added for iterators, 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.
Iteration doesn’t require an underlying data structure, and doesn’t even have to be finite! Here’s a function returning an iterator over Fibonacci numbers: it keeps running as long as yield keeps returning true.
Since List.All returns an iterator, we can use it in a regular loop.
Here’s a sample output you might see after running this Cilk program:
Now that we can run and build basic Cilk programs with iterators, let’s learn more about the language.