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

ZipIterator

Owns two cursors and lazily pairs items until either input ends.

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.

ZipIterator

pub final class ZipIterator<L, R, LI, RI>
    where L: Movable where R: Movable
    where LI: TypedIterator<L>, Movable where RI: TypedIterator<R>, Movable

Owns two cursors and lazily pairs items until either input ends.

Each pull advances left first, then right. If left ends, right is untouched; if right ends, the already-pulled unmatched left item is discarded normally. No rollback, lookahead allocation or synchronization occurs. Construction performs no pulls. Exhaustion is sticky. Exact references retain access and expire with their respective source backing, owned elsewhere. L: Exact Movable left value/reference item. R: Exact Movable right value/reference item. LI: Structural left cursor returning L?. RI: Structural right cursor returning R?.

Example

module example.zip_iterator;
from std.iteration import Zip;
fn Main() -> i32 {
    let Inputs: i32[2] = [20, 22];
    var Outputs: i32[3] = [0, 0, 99];
    var Cursor = Zip<i32&, mut i32&>(Inputs.CreateIterator(), Outputs.CreateWritableIterator());
    while Cursor.Next() is .Some { Value = Pair } { Pair.Right = Pair.Left; }
    if Outputs[0] != 20 || Outputs[1] != 22 || Outputs[2] != 99 { return 1; }
    return 0;
}

ZipIterator.Next

pub fn Next() -> ZipItem<L, R>?

Pulls left then right and returns their exact ordered pair. Return: Pair, or sticky none after either input ends. Warning: Right exhaustion may consume one unmatched left item; aliases retain source rules.

Zip

pub fn Zip<L, R, LI, RI>(mut Left: LI, mut Right: RI) -> ZipIterator<L, R, LI, RI>
    where L: Movable where R: Movable
    where LI: TypedIterator<L>, Movable where RI: TypedIterator<R>, Movable

Creates a lazy shortest-input pair cursor with explicit left-first pulls. L: Exact Movable left item type. R: Exact Movable right item type. LI: Structural left cursor, inferred from Left. RI: Structural right cursor, inferred from Right. Left: Owned left cursor state; borrowed backing remains external. Right: Owned right cursor state; borrowed backing remains external. Return: Caller-owned allocation-free adapter with constant extra state. Warning: Serialize traversal and preserve both backing lifetimes; no implicit buffering.

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