Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

CollectibleIterator

Requires cursor items that can implicitly become destination values.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. 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.

CollectibleIterator

pub concept CollectibleIterator<Self, T>

Requires cursor items that can implicitly become destination values.

The ordinary Next operation retains its original value or reference payload. The conversion requirement proves legal value transfer, borrowed Copyable copies or numeric widening; it never implicitly moves a non-Copy referent. The concept introduces no runtime wrapper, buffer, allocation or type test. Actual traversal retains the concrete cursor's backing lifetime rules. Self: Concrete cursor with mutable traversal state. T: Destination value type, supplied by the consuming algorithm.

Example

module example.collectible_iterator;
from std.collections import Vector;
from std.iteration import CollectibleIterator, TryExtend;
fn Append<T, I>(Destination: mut Vector<T>&, mut Cursor: I) -> bool
    where T: Movable where I: CollectibleIterator<T>, Movable {
    switch TryExtend(Destination, move(Cursor)) {
        case .Ok => return true;
        case .Err { Error = _ } => return false;
    }
}
fn Main() -> i32 {
    let Source: i16[2] = [20_i16, 22_i16];
    var Values = Vector<i32>();
    if !Append(Values, Source.CreateIterator()) { return 1; }
    if Source[0] != 20_i16 || Source[1] != 22_i16 { return 2; }
    return Values.At(0) + Values.At(1) - 42;
}

CollectibleIterator.Item

associated type Item;

Identifies the original owned or borrowed item, preserving access.

CollectibleIterator.Next

requires fn Next() -> Item?;

Advances once, preserving the original item ownership. Return: Some item, or None after exhaustion; backing follows the concrete cursor.

CollectibleIterator.requirement

requires Item -> T;
Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library