BorrowingCallableWhereIterator
Owns lazy filtering state and a concrete safe predicate environment.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
BorrowingCallableWhereIterator
pub final class BorrowingCallableWhereIterator<T, I, C>
where T: Movable where I: TypedIterator<T>, Movable
where C: BorrowingUnaryCallable<T, bool>, MovableOwns 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 Movable 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.borrowingcallablewhereiterator;
from std.iteration import Where, Count, Find, Any, All;
fn Main() -> i32 {
let Threshold: i32 = 0;
let Positive = (Item: readonly 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;
}BorrowingCallableWhereIterator.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) -> BorrowingCallableWhereIterator<T, I, C>
where T: Movable where I: TypedIterator<T>, Movable
where C: BorrowingUnaryCallable<T, bool>, MovableCreates allocation-free lazy filtering with a concrete predicate. T: Exact Movable 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.