
Iterate over a priority_queue (coro iterator)
Source: R/30-api-flexseq-iter.R
as_iterator.priority_queue.RdReturns a lazy iterator that yields payload elements in priority-ascending
order. Use with loop():
Details
Traversal is driven by repeated pop_min(): each step is O(log n), so full
traversal is O(n log n). Ties within equal priorities are yielded in FIFO
insertion order (inherited from pop_min()).
The original x is not modified; the iterator holds a private cursor and
partial iteration (e.g. via break) leaves the source intact.
Each yielded value is the bare payload (matching peek_min()). Use
fapply() if your callback needs the priority alongside the value, or cast
with as_flexseq() for insertion-order iteration.
Examples
pq <- priority_queue("a", "b", "c", priorities = c(3, 1, 2))
loop(for (x in pq) print(x)) # "b", "c", "a"
#> [1] "b"
#> [1] "c"
#> [1] "a"