ListMap

Used to iterate over a delimited list and run the function closure for each item in the list and create a new list from the returned values.

Method Signature

ListMap(list=[string], callback=[function:Function], delimiter=[string], includeEmptyFields=[boolean], parallel=[boolean], maxThreads=[integer])

Arguments

Argument
Type
Required
Description
Default

list

string

true

The delimited list to perform operations on

callback

function:Function

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 Function which will only receive the 1st arg.

delimiter

string

false

string the list delimiter

,

includeEmptyFields

boolean

false

boolean whether to include empty fields in the returned result

false

parallel

boolean

false

false

maxThreads

integer

false

Examples

Script Syntax

Run Example

Rainbow = "Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero";
externalList = "";
reverseRainbow = listMap( rainbow, ( Any v, Any i, Any l ) => {
	var newValue = "#i#:#v.reverse()#";
	externalList = externalList.listAppend( newValue );
	return newValue;
} );
writeDump( [
	{
		RAINBOW : rainbow
	},
	{
		REVERSERAINBOW : reverseRainbow
	},
	{
		EXTERNALLIST : externalList
	}
] );

Additional Examples

Run Example

fruits = "apple,pear,orange";
writedump( fruits );
fruitsPlural = listMap( fruits, ( Any value, Any index, Any list ) => {
	return value & "s";
} );
writedump( fruitsPlural );

Last updated

Was this helpful?