pub fn value_or<K, V>(map: &HashMap<K, V>, key: &K, fallback: V) -> VExpand description
Returns a value from a map for a given key, or a fallback value if the key doesn’t exist.
§Arguments
map- The map to get the value fromkey- The key to look upfallback- The value to return if the key doesn’t exist
§Returns
V- Either the value from the map or the fallback value
§Examples
use lowdash::value_or;
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert("a", 1);
assert_eq!(value_or(&map, &"a", 42), 1);
assert_eq!(value_or(&map, &"b", 42), 42);