4 ms·
zip is generally implemented as a functional concept, where the iterators take values from the backing iterable structure "by const &". You can implement a cust
by qsort 4y ago
zip is generally implemented as a functional concept, where the iterators take values from the backing iterable structure "by const &". You can implement a custom mutating zip operation on top of the iterator protocol.
- greenpeas 4y agoI believe masklinn is talking about whether `zip` consumes an extra element from the longer iterator on the last iteration, when the shorter iterator raises StopIteration. And the behavior might vary depending on the order of the arguments. def a(): yield "a1" def b(): yield "b1" yield "b2" x,y = a(),b() zip(x,y) # => [("a1","b1")] next(x) # => raise StopIteration next(y) # => "b2" x,y = a(),b() zip(y,x) # => [("b1","a1")] next(x) # => raise StopIteration next(y) # => raise StopIteration