Skip to content
PeerHeer edited this page Dec 31, 2019 · 1 revision

Description

The listutils:map function applies a function to each element in a list.

Usage

Input is given using the listutils:in storage:

Field Meaning
List The list to map.

Optionally, a map function can be specified in the $listutils.function listutils.in score. This argument defaults to function 0, which returns a copy of each element.

After defining the input, run the function listutils:map.

Map functions

Various map functions can be used to map elements. For more about map functions, see the Map functions page.

Errors

Errors that display when executing the listutils:map function as a player in debug mode.

Error Message
TBD TBD

Return values

Success

The success of the operation is stored in the $listutils.success listutils.out score. This score is 1 on success and 0 otherwise. By default, the success is always 1 when not running in debug mode. This can be changed in the map function.

Result

The result of the operation is stored inside the List field in the listutils:out storage and contains the mapped list.

Example

Take the example list ExampleList: [1, 2, 3, 4] in the listutils:examples storage. Say we have created a map function with ID 100 that squares each element in the list:

# Add List to the input.
data modify storage listutils:in List set from storage listutils:examples ExampleList
# Add the map function to the input.
scoreboard players set $listutils.function listutils.in 100
# Call the function.
function listutils:map

This would return the list [1, 4, 9, 16] in the List field in the listutils:out storage.

Clone this wiki locally