For the complete documentation index, see llms.txt. This page is also available as Markdown.

BoxSetReduce

Left-fold a Set with an accumulator function, reducing it to a single value.

The callback receives the current accumulator, the element value, its 1-based ordinal position, and the Set itself, and returns the new accumulator. Iteration follows the natural order of the underlying variant.

Method Signature

BoxSetReduce(set=[set], callback=[function:BiFunction], initialValue=[any])

Arguments

Argument
Type
Required
Description
Default

set

set

true

The set to reduce.

callback

function:BiFunction

true

Receives {@code (accumulator, value, ordinal, set)} and returns the new accumulator.

initialValue

any

false

The starting accumulator value. If omitted, the first element is used as the initial value.

Examples

Sum all elements with reduce

The callback receives an accumulator and the current value. The third argument is the initial accumulator value.

s = [ 1, 2, 3, 4, 5 ].toSet();
total = s.reduce( ( Any acc, Any v ) => acc + v, 0 );
writeOutput( total );

Result: 15

Build a comma-separated string

Result: apple,banana,cherry

Last updated

Was this helpful?