ListReduce

Run the provided udf over a delimited list to reduce the values to a single output

Method Signature

ListReduce(list=[string], callback=[function:BiFunction], initialValue=[any], delimiter=[string], includeEmptyFields=[boolean], multiCharacterDelimiter=[boolean])

Arguments

Argument
Type
Required
Description
Default

list

string

true

The delimited list to perform operations on

callback

function:BiFunction

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java BiFunction which will only receive the ffirst 2 args.

initialValue

any

false

The initial value of the reduction

delimiter

string

false

string the list delimiter

,

includeEmptyFields

boolean

false

boolean whether to include empty fields in the returned result

false

multiCharacterDelimiter

boolean

false

boolean whether the delimiter is multi-character

true

Examples

Script Syntax

Run Example

numbers = "1,2,3,4,5,6,7,8,9,10";
sum = listReduce( numbers, ( Any previousValue, Any value ) => {
	return previousValue + value;
}, 0 );
writeOutput( "The sum of the digits #numbers# is #sum#<br>" );

Additional Examples

Run Example

numbers = "1,3,5,7";
reducedVal = listReduce( numbers, ( Any previousValue, Any value ) => {
	return previousValue + value;
}, 0 );
writeOutput( "The sum of the digits #numbers# is #reducedVal#" );

Last updated

Was this helpful?