ListReduceRight

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

Method Signature

ListReduceRight(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 first 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

Simple listReduceRight Example

Demonstrate how the function works from right to left.

Run Example

myList = "a,b,c,d";
newList = listReduceRight( myList, ( Any prev, Any next, Any idx, Any arr ) => {
	return prev & next & idx;
}, "" );
writedump( newList );

Result: d4c3b2a1

listReduceRight as a Member Function

Demonstrate the member function.

Run Example

myList = "a,b,c,d";
newList = myList.listReduceRight( ( Any prev, Any next, Any idx, Any arr ) => {
	return prev & next & idx;
}, "" );
writedump( newList );

Result: d4c3b2a1

Empty Elements

Demonstrate the behavior when there is an empty element.

Run Example

myList = "a,,,,,b,,,c,,,d";
newList = myList.listReduceRight( ( Any prev, Any next, Any idx ) => {
	return prev & next & idx;
}, "" );
writedump( newList );

Result: d4c3b2a1

Last updated

Was this helpful?