Closed
Description
Feature gate: #![feature(vec_pop_if)]
This feature adds the Vec::pop_if
method, which takes a predicate, evaluates it with the last element in the Vec
if present, and returns the item if the predicate returns true
. This makes it possible to conditionally remove the last element without the use of unwrap
.
Public API
impl<T> Vec<T> {
pub fn pop_if(&mut self, f: impl FnOnce(&mut T) -> bool) -> Option<T>;
}
Steps / History
- ACP:
pop_if
orEntry
/Peek
-like API forVec
andVecDeque
libs-team#208 - Implementation: Implement
Vec::pop_if
#123107 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Do we want a
VecDeque::pop_front_if
andVecDeque::pop_back_if
API under this as well?- Separate tracking issue: Tracking Issue for
VecDeque::pop_front_if
&VecDeque::pop_back_if
#135889
- Separate tracking issue: Tracking Issue for