-
Notifications
You must be signed in to change notification settings - Fork 0
Map
The listutils:map function applies a function to each element in a list.
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.
Various map functions can be used to map elements. For more about map functions, see the Map functions page.
Errors that display when executing the listutils:map function as a player in debug mode.
| Error | Message |
|---|---|
| TBD | TBD |
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.
The result of the operation is stored inside the List field in the listutils:out storage and contains the mapped list.
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:mapThis would return the list [1, 4, 9, 16] in the List field in the listutils:out storage.