The current implementation of next()
makes use of Peekable
. Both iterators get peeked and a comparator is used to decide which element is picked / which iterator gets advanced.
The main difficulty when implementing next_back()
for DoubleEndedIterator
would be that Peekable
only allows peeking the front and not the back. The MergeBy struct would either manually have to store the front and back peeked values or use a data structure like DoubleEndedPeekable.
If we could peek the back, the rest of the implementation would be straightforward, only the comparator's return value would need to be negated when iterating from the back.