Logo

Programming-Idioms

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

Idiom #52 Check if map contains value

Determine whether the map m contains an entry with the value v, for some key.

Is this value contained in this map, for any key?
use std::collections::BTreeMap;
let does_contain = m.values().any(|&val| *val == v);

Works the same for HashMap.
(boolean (some #{v} (vals m)))

In Clojure values are truthy/falsy

no need for boolean, however included due to other language examples

New implementation...