Skip to content

Add Enumerator for writing iterators

Yorick Peterse requested to merge enumerators into master

Details

The new type std::iterator::Enumerator makes it much easier to write iterators and removes the need for having to define an object for every kind of iterator. We also add std::iterator.index_enumerator, which makes it easy to write an Enumerator/Iterator for a range based collection such as an Array.

An alternative approach to making it easier to write iterators would be to use generators, backed by either a coroutine or a continuation. Unfortunately, both continuations and coroutines come with various drawbacks that make them unappealing for Inko. Both require invasive and extensive changes to the VM, as well as parser and compiler changes. Worse, there's no real use case for both outside of generators, which makes it feel redundant to add continuations and/or coroutines.

Introducing the Enumerator type removes the need for adding more VM instructions and complexity, at the cost of writing iterators requiring a little bit more work compared to using generators.

Fixes #146 (closed)

Corresponding issue

#146 (closed)

Checklist

Edited by Yorick Peterse

Merge request reports