Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

TypedIterator

Names an exact cursor item type without external associated-type projection.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.iteration

import std.iteration;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

TypedIterator

pub concept TypedIterator<Self, T>

Names an exact cursor item type without external associated-type projection.

Satisfaction is structural and introduces no runtime witness. A Next result may own a value or borrow an exact readonly/writable reference; neither the concept nor its adapters extend backing storage lifetime. Implementations document thread affinity and invalidation; concurrent mutation needs their own synchronization contract. Self: Concrete mutable traversal state. T: Exact item type, including its reference access when applicable.

Example

module example.typed_iterator;
from std.iteration import Take, Skip, Count;
fn Main() -> i32 {
    let Range = 0_i32..5_i32;
    var Tail = Skip<i32>(Range.CreateIterator(), 2);
    var Prefix = Take<i32>(move(Tail), 2);
    var Total: i32 = 0;
    while Prefix.Next() is .Some { Value = Item } { Total += Item; }
    if Total != 5 { return 1; }
    if Count(Range.CreateIterator()) != 5 { return 2; }
    return 0;
}

TypedIterator.Next

requires fn Next() -> T?;

Advances the cursor and returns its exact value/reference item. Return: One optional item; owning payloads require ordinary deterministic cleanup.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library