Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

EnumerateIterator

Owns lazy cursor state that attaches checked indices to each item.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. 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.

EnumerateIterator

pub final class EnumerateIterator<T, I>
    where T: Movable where I: TypedIterator<T>, Movable

Owns lazy cursor state that attaches checked indices to each item.

Construction pulls nothing and allocates nothing. Traversal owns its source cursor, adds constant state, and preserves exact Movable value/reference access. Source backing lifetime and synchronization remain the caller's responsibility. The first source none latches exhaustion. No index wraps: an attempted successor to usize maximum uses normal checked arithmetic. T: Exact Movable value/reference item type. I: Structural owned cursor returning T?.

Example

module example.enumerate_iterator;
from std.iteration import Enumerate;
fn Main() -> i32 {
    var Values: i32[2] = [20, 20];
    var Cursor = Enumerate<mut i32&>(Values.CreateWritableIterator(), 1);
    while Cursor.Next() is .Some { Value = Item } {
        Item.Value += Item.Index as i32;
    }
    if Values[0] != 21 || Values[1] != 22 { return 1; }
    return 0;
}

EnumerateIterator.Next

pub fn Next() -> IndexedItem<T>?

Pulls one item and attaches its checked sequence index. Return: Exact value/reference item and index, or sticky none. Warning: A successful successor beyond usize maximum fatal-traps; aliases retain source lifetime.

Enumerate

pub fn Enumerate<T, I>(mut Source: I, Start: usize) -> EnumerateIterator<T, I>
    where T: Movable where I: TypedIterator<T>, Movable

Creates a lazy indexed cursor beginning at an explicit seed. T: Exact Movable item type, including reference access. I: Structural source cursor type, inferred from Source. Source: Owned cursor state; move a non-Copy cursor explicitly. Start: Index of the first delivered item; checked successors never wrap. Return: Caller-owned allocation-free adapter, preserving source backing rules.

Enumerate

pub fn Enumerate<T, I>(mut Source: I) -> EnumerateIterator<T, I>
    where T: Movable where I: TypedIterator<T>, Movable

Creates a lazy indexed cursor beginning at zero. T: Exact Movable item type, including reference access. I: Structural source cursor type, inferred from Source. Source: Owned cursor state, transferred without a pull or allocation. Return: Caller-owned adapter; borrowed backing must survive all yielded aliases.

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