Thanks to visit codestin.com
Credit goes to github.com

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

Description

The listutils:filter function filters the list according to the truth value of the elements.

Usage

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.

Filter functions

Various filter functions can be used to filter elements. For more about filter functions, see the Filter functions page.

Errors

Errors that display when executing the listutils:filter 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 filter function.

Result

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

Example

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:filter

This would return the list ["Hello World!", "bar"] in the List field in the listutils:out storage.

Clone this wiki locally