Algosim documentation: RemoveIf

RemoveIf

Removes, from a container, every element that satisfy a given predicate.

Syntax

Description

If X is any container (including a set), then RemoveIf(X, p) returns X with every element x for which p(x) is true removed. If X is not a set, then RemoveIf(X, p, n) removes elements that satisfy p at level n, with level n = 1 being X itself.

Examples

v ≔ RandomIntVector(20, −3, 4)
(2, −2, 1, −2, 3, 1, −2, 0, −3, 3, 1, 3, 3, 1, −2, 2, 0, 0, 3, 3)
RemoveIf(v, odd)
(2, −2, −2, −2, 0, −2, 2, 0, 0)
compute(RandomIntVector(20, −3, 4), n, 1, 5)
(−1, −3, −2, 1, 1, 2, −1, −3, 2, 3, 2, −3, 2, −2, −3, 3, 1, −3, −1, −1)
(2, −1, 3, 3, 0, −2, 0, 1, 0, −2, 2, −3, −1, 3, 1, 0, −3, 1, 3, 1)
(1, 0, 3, −2, −1, 2, 2, 3, 1, 1, 1, −2, −2, −1, −1, −3, 3, −1, 0, 3)
(−1, −1, 0, 3, 2, 1, 3, 0, 2, −1, −2, 1, 2, 3, −2, 2, 0, 2, 0, −1)
(2, −1, 2, 3, 2, 2, −2, 0, 0, 1, −1, −3, 2, −1, 1, 1, 0, 0, 3, −1)
RemoveIf(ans, odd, 2)
(−2, 2, 2, 2, 2, −2)
(2, 0, −2, 0, 0, −2, 2, 0)
(0, −2, 2, 2, −2, −2, 0)
(0, 2, 0, 2, −2, 2, −2, 2, 0, 2, 0)
(2, 2, 2, 2, −2, 0, 0, 2, 0, 0)

See also