diff --git a/src/lib.rs b/src/lib.rs
index ab9b4ab..9b9d565 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -298,4 +298,16 @@ pub mod hashmap {
}
}
}
+
+ /// Merge recursively elements if the key is present in `left` and `right`.
+ pub fn intersection<K: Eq + Hash, V: crate::Merge>(left: &mut HashMap<K, V>, right: HashMap<K, V>) {
+ use std::collections::hash_map::Entry;
+
+ for (k, v) in right {
+ match left.entry(k) {
+ Entry::Occupied(mut existing) => existing.get_mut().merge(v),
+ _ => {}
+ }
+ }
+ }
}