Hey all, I’ve been directed to move this here since it doesn’t need a full-blown RFC.
I’m adding an interleaving iterator to the set of core iterator adaptors. That is
a1,b1,a2,b2,... until one terminates.
There’s no easy way to accomplish this with the current set of iterator adaptors, and there are enough subtle corner cases that I wouldn’t expect someone to trivially implement it correctly when they need it.
Off the top of my head, this is desirable for when something expects a single iterator, but you want to interleave the contents of multiple iterators. For instance, if you wanted to create a stream of loosely unsorted data, you could do something like
I’ve actually fully implemented this in this pull request, this is sort of a retroactive RFC-ish thing to see if this is in fact desirable to have in libcore at all.
My biggest open question on the whole thing is that it’s possible to have interleave not terminate when any one of the source iterators terminates, but rather just output the rest of the remaining iterator. This would increase complexity, and is not clearly desirable. In this vein, Interleave could potentially be augmented to provide all kinds of combinations of behaviour, such as offsetting the splicing of the iterators
(a1, a2, a3, b1, a4, b2, a5, b3, ...) or unbalanced usage of the sources
(a1, a2, b1, a3, a4, b2...).
Would we want any of these in addition or instead of my current default behaviour?