Method in collections::map · HashMap coil-stdlib

HashMap::get_or

pub fn get_or(K k, V fallback) -> V
Import
use collections::map::{HashMap};
Source: src/collections/map.hy

Returns the value stored under k, or fallback when there is none.

Called on a HashMap value as value.get_or(…).

Parameters#

NameType
kK
fallbackV

Returns#

V

Examples#

use collections::map::{HashMap};
use tests::assert;
let m: HashMap<string, int> = HashMap::new();
m.insert("a", 1);
assert!(m.get_or("a", 0) == 1);
assert!(m.get_or("b", 0) == 0);

See also#

↑ ↓ navigate ↵ open