map_object

Function map_object 

Source
pub fn map_object<K: Eq + Hash + Clone, V, F: Fn(&V) -> U, U>(
    obj: &HashMap<K, V>,
    fun: F,
) -> HashMap<K, U>
Expand description

Maps a hashmap with a function.

Applies a function to each value in the hashmap.

§Arguments

  • obj - The hashmap.
  • fun - The function to apply.

§Returns

New hashmap with transformed values.

§Examples

use gf_core::map_object;
use std::collections::HashMap;
let mut map: HashMap<String, i32> = HashMap::new();
map.insert("a".to_string(), 1);
let new_map = map_object(&map, |&v| v * 2);
assert_eq!(new_map.get("a"), Some(&2));