% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/30-api-flexseq-iter.R
\name{as_iterator.priority_queue}
\alias{as_iterator.priority_queue}
\title{Iterate over a \code{priority_queue} (coro iterator)}
\usage{
\method{as_iterator}{priority_queue}(x)
}
\arguments{
\item{x}{A \code{priority_queue}.}
}
\value{
A \code{coro} iterator function.
}
\description{
Returns a lazy iterator that yields payload elements in priority-ascending
order. Use with \code{\link[=loop]{loop()}}:
}
\details{
\if{html}{\out{<div class="sourceCode">}}\preformatted{loop(for (x in pq) print(x))
}\if{html}{\out{</div>}}

Traversal is driven by repeated \code{\link[=pop_min]{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 \code{\link[=pop_min]{pop_min()}}).

The original \code{x} is not modified; the iterator holds a private cursor and
partial iteration (e.g. via \code{break}) leaves the source intact.

Each yielded value is the bare payload (matching \code{\link[=peek_min]{peek_min()}}). Use
\code{\link[=fapply]{fapply()}} if your callback needs the priority alongside the value, or cast
with \code{\link[=as_flexseq]{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"
}
