Any
Tests whether a cursor contains a safe-predicate match.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
Any
pub fn Any<T, I>(mut Cursor: I, Predicate: fn(T) -> bool) -> bool
where T: Copyable
where I: TypedIterator<T>Tests whether a cursor contains a safe-predicate match.
Stops after the first true predicate result or exhaustion; empty input returns false. No intermediate allocation or backing retention occurs. Source and callback costs, side effects and synchronization remain their own contracts. T: Exact Copyable input value/reference category. I: Structural cursor type inferred from Cursor. Cursor: Traversal state; explicitly move a non-Copy cursor. Predicate: Safe function tested once per examined item. Return: True at the first match; false on first source exhaustion. Warning: Does not examine later items after a match or extend reference lifetimes.
Example
module example.any_iterator;
from std.iteration import Any;
fn Positive(Value: i32&) -> bool { return Value > 0; }
fn Main() -> i32 {
let Values: i32[3] = [-1, 0, 42];
if !Any<i32&>(Values.CreateIterator(), Positive) { return 1; }
let Empty: i32[0] = [];
if Any<i32&>(Empty.CreateIterator(), Positive) { return 2; }
return 0;
}Any
pub fn Any<T, I>(mut Cursor: I, Predicate: fn(readonly T&) -> bool) -> bool
where T: Movable where I: TypedIterator<T>Consumes a cursor with a safe predicate that borrows each exact item.
Owns each optional carrier during callback evaluation, avoiding non-Copy payload copies. Examined non-returned items receive ordinary destruction. Traversal is ordered and synchronous with no intermediate allocation or lock. T: Exact Movable source item type. I: Structural cursor, inferred from Cursor. Cursor: Owned traversal state, consumed through first exhaustion or short circuit. Predicate: Safe readonly observer; backing validity remains its source contract. Return: Short-circuit boolean result; empty input returns false. Warning: Callback cost and reference backing lifetime remain explicit; no implicit ownership retention.