remove

This function removes and returns the value of the first item in the list that satisfies the callback function. Otherwise nil is returned if no alternative return value is specified.

This function generates an event (except when called on a variable).

Function

list.remove(callback, [alt])

Arguments

Argument Type Description
callback closure Closure to execute on each value until the closure evaluates to true.
alt any (optional) Alternative value which is returned if no item has passed the callback test.

Explanation of the callback argument:

Iterable Arguments Description
list item, index Iterate over items in the list. Both item and index are optional.

The alt argument will be lazily evaluated. Consider the following example:
elems.remove(|e| (e.name == "foo"), items.pop());
Here, the item will only be popped, in case e with name foo is not found in elems.

Return value

The value of the first item in the list that satisfies the provided testing function; otherwise, nil or a specified alternative value is returned.

Example

This code shows an example using remove() on a list:

tmp = [1, 2, 3, 4];
[
    tmp.remove(|x| (x % 2 == 0)),
    tmp,
];

Return value in JSON format

[
    2,
    [
        1,
        3,
        4
    ]
]