-
Notifications
You must be signed in to change notification settings - Fork 0
Filter
The listutils:filter function filters the list according to the truth value of the elements.
Input is given using the listutils:in storage:
| Field | Meaning |
|---|---|
List |
The list to filter. |
Optionally, a filter function can be specified in the $listutils.function listutils.in score. This argument defaults to function 0, which filters elements according to their data get value.
After defining the input, run the function listutils:filter.
Various filter functions can be used to filter elements. For more about filter functions, see the Filter functions page.
Errors that display when executing the listutils:filter 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 filter function.
The result of the operation is stored inside the List field in the listutils:out storage and contains the filtered list.
Take the example list ExampleList: ["", "Hello World!", "", "bar"] in the listutils:examples storage. We want to filter the elements according to their data get value:
# Add List to the input.
data modify storage listutils:in List set from storage listutils:examples ExampleList
# Add the filter function to the input.
scoreboard players set $listutils.function listutils.in 0
# Call the function.
function listutils:filterThis would return the list ["Hello World!", "bar"] in the List field in the listutils:out storage.