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

CallableWhereIterator

Owns lazy filtering state and a concrete safe predicate environment.

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.

CallableWhereIterator

pub final class CallableWhereIterator<T, I, C>
    where T: Copyable where I: TypedIterator<T>, Movable
    where C: UnaryCallable<T, bool>, Movable

Owns lazy filtering state and a concrete safe predicate environment.

Construction does not pull or invoke the predicate. Each Next searches in source order until a match or exhaustion; rejected carriers are destroyed before another pull. First none latches exhaustion. No intermediate container, allocation, lock or type-erased callback box is introduced. Retained item carriers preserve exact ownership/access; borrowed captures and item backing retain their original lifetime and invalidation contracts. Serialize cursor access and honor callback synchronization restrictions. T: Exact Copyable source item type. I: Owned structural cursor returning T?. C: Concrete Movable safe readonly predicate. Warning: Infinite input without matches may never produce another result.

Example

module example.callablewhereiterator;
from std.iteration import Where, Count, Find, Any, All;
fn Main() -> i32 {
    let Threshold: i32 = 0;
    let Positive = (Item: i32) => Item > Threshold;
    let Range = -1_i32..3_i32;
    var Filtered = Where<i32>(Range.CreateIterator(), Positive);
    if Count(move(Filtered)) != 2 { return 1; }
    switch Find<i32>(Range.CreateIterator(), Positive) {
        case .Some { Value = Item } => { if Item != 1 { return 2; } }
        case .None => return 3;
    }
    if !Any<i32>(Range.CreateIterator(), Positive) { return 4; }
    if All<i32>(Range.CreateIterator(), Positive) { return 5; }
    return 0;
}

CallableWhereIterator.Next

pub fn Next() -> T?

Searches for a match while retaining each candidate carrier. Return: Exact matching item carrier or sticky none on exhaustion. Warning: Callback and discarded-item costs are additional; backing lifetimes do not extend.

Where

pub fn Where<T, I, C>(mut Source: I, mut Predicate: C) -> CallableWhereIterator<T, I, C>
    where T: Copyable where I: TypedIterator<T>, Movable
    where C: UnaryCallable<T, bool>, Movable

Creates allocation-free lazy filtering with a concrete predicate. T: Exact Copyable item type, supplied explicitly. I: Structural source cursor, inferred from Source. C: Concrete safe predicate, inferred from Predicate. Source: Owned traversal state; explicitly move non-Copy named state. Predicate: Owned callback; borrowed captures must survive cursor use. Return: Owned lazy adapter retaining original item ownership/access. Warning: Construction does not search; each pull may examine arbitrarily many items.

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