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

BorrowingWhereIterator

Owns lazy filtering state that borrows each candidate without copying it.

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.

BorrowingWhereIterator

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

Owns lazy filtering state that borrows each candidate without copying it.

Exact Movable payloads remain owned by a retained optional until accepted or destroyed. The safe predicate receives readonly access; a successful Next transfers the carrier and its original ownership/access. No clone, allocator or synchronization is introduced. Backing lifetimes remain external for reference items. Serialize cursor use and honor source invalidation rules. T: Exact Movable source item type, including non-Copy owning objects. I: Structural source cursor returning T?.

Example

module example.borrowed_predicates;
from std.iteration import Where, Find, Any, All, Count;
fn Positive(Item: readonly i32&) -> bool { return Item > 0; }
fn Main() -> i32 {
    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;
}

BorrowingWhereIterator.Next

pub fn Next() -> T?

Searches by readonly borrowing and transfers the first matching carrier. Return: Original exact owned/reference item, or sticky none after exhaustion. Warning: Rejected owning items are destroyed before another pull; source aliases keep original lifetime.

Where

pub fn Where<T, I>(mut Source: I, Predicate: fn(readonly T&) -> bool)
    -> BorrowingWhereIterator<T, I>
    where T: Movable where I: TypedIterator<T>, Movable

Creates a lazy filter using a safe readonly-borrowing predicate. T: Exact Movable source item type. I: Structural source cursor, inferred from Source. Source: Owned traversal state, moved explicitly when non-Copy. Predicate: Safe observer of a retained live payload; must honor backing validity. Return: Owned allocation-free cursor preserving original item ownership and access. Warning: No implicit cloning, capture ownership or synchronization is added.

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