Logo

Programming-Idioms

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

Idiom #140 Delete map entry

Delete from map m the entry having key k.

Explain what happens if k is not an existing key in m.

m - k

The map m is not mutated, and a new map is returned instead. If k doesn't exist in m, no error occurs. The default implementation of Map is a HashMap.
m -= k

This mutates the map m, removing k from it. If k doesn't exist in m, no error occurs. Only available on mutable Map. The default implementation of Map is a HashMap.
(dissoc m k)

Returns a new map without the key k. If k doesn't exist the original map is returned unaltered.

New implementation...
< >
programming-idioms.org