You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please add a new method pop_if() that removes and returns the "top" element from the queue as a Some((item, priority)), but only if the "top" element matches the given predicate. Otherwise, a None should be returned.
The rationale is that currently we need to write a code like this:
while queue.peek().is_some_and(|(item, priority)| some_condition(...)){(item, priority) = queue.pop().unwrap();/* ... */}
But the unwrap() is kind of ugly, because it shouldn't actually be needed. That is because, at this point, we already know for sure there is a next element. But, even more important, the peek() to investigate the "top" element plus the additionalpop() to actually remove it, requires two lookups – where this operation should be possible with just a single one!
Originally posted by @lordmulder in #55
The text was updated successfully, but these errors were encountered: