View source: R/30-api-flexseq-iter.R
| as_iterator.flexseq | R Documentation |
flexseq (coro iterator)Returns a lazy iterator that yields payload elements left-to-right.
Use with loop() as the canonical iteration form:
## S3 method for class 'flexseq'
as_iterator(x)
x |
A |
loop(for (x in s) print(x))
Iteration uses repeated left-view (viewL) and is O(n) total, O(1) amortized
per step. The original 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 peek_front(s) semantics. Access names via as.list() when needed.
Inherited by ordered_sequence and interval_index: for those subclasses
the yielded value is the unwrapped payload (keys / interval endpoints
dropped), in key-ascending / start-position order respectively. See
as_iterator.priority_queue() for the priority-order override.
A coro iterator function.
for directlyWriting for (x in s) ... (without loop()) will not dispatch this method.
R's for walks the object's underlying list storage at the C level and
bypasses S3 length/[[, so it silently yields raw finger-tree internals
(Digit/Empty/Deep nodes) rather than sequence elements. Always wrap with
loop(), or call as.list() first for an eager copy.
s <- flexseq("a", "b", "c")
loop(for (x in s) print(x))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.