Inspired by this Reddit comment, although it turned out that pop_if
already exist on nightly.
Vec::extract_if
, combined with take
or take_while
can be used as generalized pop_if
, ie. a conditional removal of zero or more elements from one of the ends of the vector – except that extract_if
extracts from the front and pop_if
from the back. The latter is, of course, also more efficient. The ExtractIf
iterator does not impl DoubleEndedIterator
although to me it seems it could. Does anyone see any problems with adding such an impl?
(Also, VecDeque
would also benefit from having an extract_if
, although to match the rest of the API there should probably be separate extract_front_if
and extract_back_if
.)