omit_by_keys

Function omit_by_keys 

Source
pub fn omit_by_keys<K, V>(map: &HashMap<K, V>, keys: &[K]) -> HashMap<K, V>
where K: Eq + Hash + Clone, V: Clone,
Expand description

Filters a map by omitting specified keys.

Iterates over the provided keys and removes them from a cloned version of the input map. Only key-value pairs not present in the keys slice are included in the result map.

§Arguments

  • map - The input map to filter.
  • keys - A slice of keys to omit from the result map.

§Returns

  • HashMap<K, V> - A new map containing only the key-value pairs that are not in the keys slice.

§Examples

use lowdash::omit_by_keys;
use std::collections::HashMap;

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

let keys = vec!["b", "d"];
let result = omit_by_keys(&map, &keys);
assert_eq!(result.len(), 2);
assert!(result.contains_key("a"));
assert!(result.contains_key("c"));
assert!(!result.contains_key("b"));