Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #136 Remove all occurrences of a value from a list

Remove all occurrences of the value x from list items.
This will alter the original list or return a new list, depending on which is more idiomatic.

items = items.into_iter().filter(|&item| item != x).collect();

This creates a new list.
items.retain(|&item| item != x);

items has type Vec.

retain operates in place.
(remove #{x} items)

Puts the x value in a set that serves as simple predicate

New implementation...