Logo

Programming-Idioms

History of Idiom 52 > diff from v31 to v32

Edit summary for version 32 by ridiculous:
[Rust] simplified

Version 31

2019-10-14, 12:25:20

Version 32

2019-11-19, 17:58:19

Idiom #52 Check if map contains value

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

Illustration

Idiom #52 Check if map contains value

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

Illustration
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()
        .find(|&val| *val == v)
        .is_some();
Code
let does_contain = m.values()
        .any(|&val| *val == v);
Comments bubble
Works the same for `HashMap`.
Comments bubble
Works the same for `HashMap`.
Demo URL
http://is.gd/qJ2pPa