map_values

Function map_values 

Source
pub fn map_values<K, V, R, F>(map: &HashMap<K, V>, iteratee: F) -> HashMap<K, R>
where K: Eq + Hash + Clone, F: Fn(&V, &K) -> R,
Expand description

Transforms the values of a map using a provided function.

§Arguments

  • map - The input map whose values are to be transformed.
  • iteratee - A function that takes a reference to a value and its key, returning a new value.

§Returns

  • HashMap<K, R> - A new map with transformed values.

§Examples

use lowdash::map_values;
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);

let transformed = map_values(&map, |&v, _k| v * 10);
assert_eq!(transformed.get("a"), Some(&10));
assert_eq!(transformed.get("b"), Some(&20));