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

Count

Consumes a structural cursor and counts items through its first exhaustion.

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.

Count

pub fn Count<I>(mut Cursor: I) -> usize where I: Iterator

Consumes a structural cursor and counts items through its first exhaustion.

Performs one Next call per item and one final exhaustion test. It allocates nothing and destroys discarded owning items normally; reference items remain nonretaining aliases. No numeric element type or external associated-type projection is required. A nonterminating source produces a nonterminating count; usize overflow uses Sn's checked arithmetic trap. Source callbacks may have their documented costs and side effects. Traversal is synchronous. I: Any structurally satisfied Iterator cursor. Cursor: Traversal state; move a non-Copy input to transfer its ownership. Return: Number of yielded items, after releasing the consumed cursor state. Warning: Does not retain backing storage or provide concurrent access protection.

Example

module example.count_iterator;
from std.iteration import Count, Take, Skip;
fn Main() -> i32 {
    let Range = 0_i32..10_i32;
    var Tail = Skip<i32>(Range.CreateIterator(), 3);
    var Prefix = Take<i32>(move(Tail), 4);
    if Count(move(Prefix)) != 4 { return 1; }
    if Count((0_i32..0_i32).CreateIterator()) != 0 { return 2; }
    return 0;
}
Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library