BoxSetEvery
Test whether every element of a Set satisfies a predicate.
Iteration short-circuits on the first element for which the predicate returns false. Returns true for an empty Set (vacuous truth). The predicate receives the element value, its 1-based ordinal position, and the Set itself.
Method Signature
BoxSetEvery(set=[set], callback=[function:Predicate])Arguments
Argument
Type
Required
Description
Default
set
set
true
The set to test.
callback
function:Predicate
true
Predicate invoked for each element. Receives {@code (value, ordinal, set)}. Short-circuits on the first {@code false} result.
Examples
Test that every element satisfies a predicate
Returns true when the callback returns true for all elements. Returns false on the first failure.
s = [ 1, 2, 3, 4 ].toSet();
allPositive = s.every( ( Any v ) => v > 0 );
allEven = s.every( ( Any v ) => v % 2 == 0 );
writeOutput( allPositive & "," & allEven );
Result: true,false
Related
Last updated
Was this helpful?
