View source: R/30-api-flexseq-iter.R
| as_iterator.priority_queue | R Documentation |
priority_queue (coro iterator)Returns a lazy iterator that yields payload elements in priority-ascending
order. Use with loop():
## S3 method for class 'priority_queue'
as_iterator(x)
x |
A |
loop(for (x in pq) print(x))
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.
A coro iterator function.
pq <- priority_queue("a", "b", "c", priorities = c(3, 1, 2))
loop(for (x in pq) print(x)) # "b", "c", "a"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.