Logo

Programming-Idioms

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

Idiom #277 Remove an element from a set

Remove the element e from the set x.

Explains what happens if e was already absent from x.

use std::collections::HashSet;
x.take(e)

x has type mut HashSet

returns Some(e) if the value was present, None otherwise
use std::collections::HashSet
x.remove(e);

x has type mut HashSet

returns true if value was present.
(disj x e)

Removing a non-existent element from a set returns back an identical set.

New implementation...