Logo

Programming-Idioms

  • Kotlin
  • C++
  • D

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?
import std.algorithm;
m.byValue.canFind(v);
m.containsValue(v)
#include <algorithm>
std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; }) != m.end();

c++ 14

A lambda expression is used because built-in functions would search by key, not by value.
(boolean (some #{v} (vals m)))

In Clojure values are truthy/falsy

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

New implementation...