std/iter

March 13, 2026 ยท View on GitHub

The std/iter module provides traits for defining custom iterators compatible with Zen C's for-in loop syntax.

Usage

import "std/iter.zc"

fn main() {
    // Assuming my_collection implements Iterable<T>
    for item in my_collection {
        // ...
    }
}

Traits

Iterator<T>

An interface for advancing through a sequence.

trait Iterator<T> {
    fn next(self) -> Option<T>;
}
MethodSignatureDescription
nextnext(self) -> Option<T>Returns Some(item) if there is a next item, or None if iteration is complete.

Iterable<T>

An interface for types that can produce an Iterator.

trait Iterable<T> {
    fn iterator(self) -> Iterator<T>;
}
MethodSignatureDescription
iteratoriterator(self) -> Iterator<T>Creates and returns an iterator for the collection.