[design question] Chainable iterators
dranikpg opened this issue Β· comments
I see you've recently rewritten the package to support go generics. Having this kinds of wrappers is really useful ππ»
You went sort of the pythonic way with passing iterators into functions. However most other languages have a chainable iterator API that is more convenient to use (js map/filter/... on arrays, java streams, c++20 ranges, rust iterators). Have you considered something smilar?
Given that Go has no inheritance (for java streams) nor trait implementations for traits (for rust iters), building a convenient chainable API is somewhat challenging. Avoiding code duplication would require one more level of abstraction - always hiding specific iterators behind an iterator wrapper.
Unfortunately a shortcoming of generics in Go is that new generic types cannot be introduced on receiver functions.
It's not possible to chain currently because of this. As an example `Filter(...).Map is not possible because map would need to introduce a new generic.