SkipIterator
Owns a lazy cursor that discards a fixed prefix on its first advance.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
SkipIterator
pub final class SkipIterator<T, I> where I: TypedIterator<T>, Movable where T: MovableOwns a lazy cursor that discards a fixed prefix on its first advance.
Construction performs no work beyond cursor transfer. The first Next makes at most Count+1 pulls before yielding; subsequent steps pull once. Exhaustion is sticky. Discarded owned values are destroyed before pulling the next item; discarded reference aliases do not transfer or destroy their referents. No intermediate allocation or extra backing retention occurs. The source's invalidation and synchronization requirements remain authoritative. T: Exact source value/reference item type. I: Structural source cursor whose Next returns T?.
Example
module example.skip_iterator;
from std.iteration import Skip, Count;
fn Main() -> i32 {
let Values: i32[4] = [10, 20, 21, 21];
var Tail = Skip<i32&>(Values.CreateIterator(), 2);
var Total: i32 = 0;
while Tail.Next() is .Some { Value = Item } { Total += Item; }
if Total != 42 { return 1; }
var Empty = Skip<i32&>(Values.CreateIterator(), 99);
if Count(move(Empty)) != 0 { return 2; }
return 0;
}SkipIterator.Next
pub fn Next() -> T?Discards the pending prefix and returns the next source item. Return: One exact value/reference item, or none after first source exhaustion. Warning: First traversal costs O(skipped items); backing invalidation is unchanged.
Skip
pub fn Skip<T, I>(mut Source: I, Count: usize) -> SkipIterator<T, I>
where I: TypedIterator<T>, Movable
where T: MovableCreates lazy prefix-discard traversal without advancing its input. T: Exact item type, supplied explicitly under v1 generic rules. I: Source cursor type inferred from Source. Source: Cursor state; transfer non-Copy ownership explicitly with move. Count: Prefix length; larger than source length yields an empty cursor. Return: Caller-owned allocation-free adapter retaining only Source's own ownership. Warning: Source backing and yielded references obey the original invalidation rules.