CallableMapIterator
Owns concrete mapping callback state without type erasure or allocation.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
CallableMapIterator
pub final class CallableMapIterator<T, R, I, C>
where T: Movable where R: Movable
where I: TypedIterator<T>, Movable where C: UnaryCallable<T, R>, MovableOwns concrete mapping callback state without type erasure or allocation.
Construction moves the source and callback without pulling or invoking them. Each successful Next transfers one exact item into the readonly safe callback and publishes its result. First source none latches exhaustion. Concrete capture values use ordinary lifecycle; borrowed captures retain their backing lifetime and cannot be made longer-lived by owning this cursor. Serialize traversal and honor both source and callback synchronization restrictions. T: Exact Movable input value/reference type. R: Exact Movable output value/reference type. I: Structural source cursor returning T?. C: Concrete Movable safe UnaryCallable<T,R> callback.
Example
module example.callable_map;
from std.iteration import Map, Count;
fn Main() -> i32 {
let Factor: i32 = 2;
let Multiply = (Value: i32) => Value * Factor;
var Cursor = Map<i32, i32>((10_i32..12_i32).CreateIterator(), Multiply);
var Total: i32 = 0;
while Cursor.Next() is .Some { Value = Item } { Total += Item; }
let Remaining = Count(move(Cursor));
if Total != 42 || Remaining != 0 { return 1; }
// Factor remains alive until after Cursor and every callback invocation.
return 0;
}CallableMapIterator.Next
pub fn Next() -> R?Pulls and maps one item through the callback's exact typed witness. Return: Owned/reference output or sticky none after source exhaustion. Warning: Borrowed output and captured backing retain their original validity boundaries.
Map
pub fn Map<T, R, I, C>(mut Source: I, mut Mapper: C) -> CallableMapIterator<T, R, I, C>
where T: Movable where R: Movable
where I: TypedIterator<T>, Movable where C: UnaryCallable<T, R>, MovableCreates a lazy cursor owning a concrete capturing or authored callback. T: Exact Movable input type, supplied explicitly. R: Exact Movable result type, supplied explicitly. I: Structural cursor, inferred from Source. C: Concrete safe UnaryCallable callback, inferred from Mapper. Source: Owned cursor state; move non-Copy state explicitly. Mapper: Concrete environment; move non-Copy captures explicitly with their owner. Return: Caller-owned allocation-free adapter retaining concrete callback lifecycle. Warning: Owning the environment does not retain borrowed capture backing or add thread safety.