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

MapIterator

Owns lazy mapping state with an exact safe function callback.

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.

MapIterator

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

Owns lazy mapping state with an exact safe function callback.

Construction does not pull or allocate. Each Next pulls at most once, calls Mapper once for a delivered item, and latches the first none. Exact input references remain aliases; owning inputs transfer into the callback and outputs may own Movable values. The callback and source determine cost, synchronization and backing lifetime; this adapter adds no retaining owner or thread safety for reference inputs/results. T: Exact Movable input value/reference type. R: Exact Movable output value/reference type. I: Owned structural cursor returning T?.

Example

module example.map_iterator;
from std.iteration import Map, Count;
fn Double(Value: i32&) -> i32 { return Value * 2; }
fn Main() -> i32 {
    let Values: i32[2] = [10, 11];
    var Cursor = Map<i32&, i32>(Values.CreateIterator(), Double);
    var Total: i32 = 0;
    while Cursor.Next() is .Some { Value = Item } { Total += Item; }
    if Total != 42 { return 1; }
    if Count(move(Cursor)) != 0 { return 2; }
    return 0;
}

MapIterator.Next

pub fn Next() -> R?

Pulls and transforms one exact input item. Return: Mapped output or none; an owned output transfers into its optional carrier. Warning: Callback side effects and borrowed result lifetimes remain its contract.

Map

pub fn Map<T, R, I>(mut Source: I, Mapper: fn(T) -> R) -> MapIterator<T, R, I>
    where T: Movable
    where R: Movable
    where I: TypedIterator<T>, Movable

Creates allocation-free lazy mapping with a safe function value. T: Exact Movable input item type, supplied explicitly. R: Exact Movable result type, supplied explicitly. I: Source cursor type inferred from Source. Source: Traversal state; move a non-Copy cursor to transfer ownership. Mapper: Safe named/noncapturing callback; called only during Next. Return: Owned adapter; source and callback retain their own lifetime requirements. Warning: Does not erase unsafe callbacks or retain borrowed input/result storage.

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