Logo

Programming-Idioms

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

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.

import std.algorithm.iteration;
import std.array;
items = items.filter!(a => a != x).array;

The result of .filter is not evaluated until it's yielded by .array

This solution works for any input range, not only arrays.
(remove #{x} items)

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

New implementation...