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

ScalarIterator

Traverses one valid UTF-8 view as Unicode scalar values.

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.

ScalarIterator

pub final class ScalarIterator

Traverses one valid UTF-8 view as Unicode scalar values.

The cursor borrows the original byte storage through a shrinking str view, allocates nothing, and performs one bounded UTF-8 decode per item. Its constructor/factory/step also support required constant evaluation when the borrowed input is evaluator-owned immutable UTF-8 storage.

Example

module example.scalar_iterator;
fn Main() -> i32 {
    var Cursor = "Aλ".CreateIterator();
    var Count = 0;
    while Cursor.Next() is .Some { Value = _ } {
        Count += 1;
    }
    // Direct range syntax uses the same authenticated scalar-cursor protocol.
    var DirectCount = 0;
    for Scalar in "Aλ" { DirectCount += 1; }
    for Scalar in "" { return 1; }
    if DirectCount != Count { return 2; }
    return Count - 2;
}

ScalarIterator.fn

pub const fn Next() -> char?

Decodes and consumes the next Unicode scalar. Return: The next scalar by value, or none when no bytes remain. Warning: The cursor remains valid only while the original backing storage remains live and unmoved.

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