-
Notifications
You must be signed in to change notification settings - Fork 0
Delete
The Delete operation finds the index of a data element. In List Utils, there are 4 functions for Delete:
- The
listutils:delete_indexfunction deletes an element at an index. - The
listutils:delete_lastfunction deletes the last matching element. - The
listutils:delete_firstfunction deletes the first matching element. - The
listutils:delete_allfunction deletes all matching elements. It is recommended to use thelistutils:delete_lastfunction instead of thelistutils:delete_firstfunction, because the former has a more efficient implementation.
Input is given using the listutils:in storage:
| Field | Meaning |
|---|---|
List |
The list that contains the element. |
Data |
The element to delete. |
When using the listutils:delete_index function, Data is not used. Instead, the $listutils.index listutils.in score should be used to pass the index to be deleted to the function. List should still be used as a list that contains the index to delete.
After defining the input, run one of the listutils:delete functions.
Various comparison functions can be used to match elements. For more about comparison functions, see the Comparison Functions page.
Errors that display when executing the listutils:delete functions 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. Success will be 0 when the list does not contain the element to delete or the index to delete is out of bounds.
The result of the operation is stored in the List field in the listutils:out storage. This result contains the list with matching element(s) deleted.
Additionally, the $listutils.result listutils.out score contains the amount of elements deleted when using delete_all.
Take the example list ExampleList: ["foo", "Hello World!", "foo", "bar"] in the listutils:examples storage. We want to delete all occurrences of "foo":
# Add List to the input.
data modify storage listutils:in List set from storage listutils:examples ExampleList
# Add Data to the input.
data modify storage listutils:in Data set value "foo"
# Call the function.
function listutils:delete_allThis would return 2 as the result in $listutils.result listutils.out (deleted 2 elements) and would yield the list ["Hello World!", "bar"].