Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

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?
func containsValue(m map[K]T, v T) bool {
	for _, x := range m {
		if x == v {
			return true
		}
	}
	return false
}
func containsValue[M ~map[K]V, K, V comparable](m M, v V) bool {
	for _, x := range m {
		if x == v {
			return true
		}
	}
	return false
}
(boolean (some #{v} (vals m)))
#include <algorithm>
std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; }) != m.end();
using System.Collections.Generic;
m.ContainsValue(v)
import std.algorithm;
m.byValue.canFind(v);
m.containsValue(v);
Map.values(m) |> Enum.member?(v)
elem v (elems m)
[...m.values()].includes(v)
Object.values(m).includes(v)
import java.util.Map;
m.containsValue(v)
m.containsValue(v)
in_array($v, $m, true);
uses fgl;
m.IndexOfData(v) >= 0
print "Found it!" if exists $m{$v};
v in m.values()
m.value?(v)
use std::collections::BTreeMap;
let does_contain = m.values().any(|&val| *val == v);
m.valuesIterator.contains(v)
m includes: v.

New implementation...