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

Iteration uses repeated left-view (\code{viewL}) and is O(n) total, O(1) amortized
per step. The original \code{x} is not modified; the iterator holds a private
cursor over progressively-smaller tails.

For named sequences, internal name metadata is stripped from yielded values
to match \code{peek_front(s)} semantics. Access names via \code{\link[=as.list]{as.list()}} when needed.

Inherited by \code{ordered_sequence} and \code{interval_index}: for those subclasses
the yielded value is the unwrapped payload (keys / interval endpoints
dropped), in key-ascending / start-position order respectively. See
\code{\link[=as_iterator.priority_queue]{as_iterator.priority_queue()}} for the priority-order override.
}
\section{Do not use plain \code{for} directly}{
Writing \code{for (x in s) ...} (without \code{\link[=loop]{loop()}}) will not dispatch this method.
R's \code{for} walks the object's underlying list storage at the C level and
bypasses S3 \code{length}/\code{[[}, so it silently yields raw finger-tree internals
(Digit/Empty/Deep nodes) rather than sequence elements. Always wrap with
\code{\link[=loop]{loop()}}, or call \code{\link[=as.list]{as.list()}} first for an eager copy.
}

\examples{
s <- flexseq("a", "b", "c")
loop(for (x in s) print(x))
}
