BoxSetFilter
Return a new Set containing only the elements of the source Set for which the predicate returns true.
The result is a new Set of the same variant as the source; the source is not modified. The predicate receives the element value, its 1-based ordinal position, and the Set itself.
Method Signature
BoxSetFilter(set=[set], callback=[function:Predicate])Arguments
Argument
Type
Required
Description
Default
set
set
true
The set to filter.
callback
function:Predicate
true
Predicate invoked for each element. Receives {@code (value, ordinal, set)}. Elements for which this returns {@code true} are included in the result.
Examples
Keep only elements that satisfy a predicate
Returns a new Set containing elements for which the callback returns true.
s = [ 1, 2, 3, 4, 5 ].toSet();
evens = s.filter( ( Any v ) => v % 2 == 0 );
writeOutput( evens.size() );
Result: 2
Filter strings by length
Result: 2
Related
Last updated
Was this helpful?
