Logo

Programming-Idioms

History of Idiom 52 > diff from v46 to v47

Edit summary for version 47 by programming-idioms.org:
[Rust] Emphasis in comments

Version 46

2020-12-14, 22:31:58

Version 47

2020-12-14, 22:32:28

Idiom #52 Check if map contains value

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

Idiom #52 Check if map contains value

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

Variables
m,v
Variables
m,v
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
use std::collections::BTreeMap;
Imports
use std::collections::BTreeMap;
Code
let does_contain = m.values()
        .any(|&val| *val == v);
Code
let does_contain = m.values()
        .any(|&val| *val == v);
Comments bubble
Works the same for `HashMap`.
Comments bubble
Works the same for HashMap.