Created
May 26, 2020 09:19
-
-
Save anacrolix/902760b8509f43f35d027b4b771ce72b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait ExtendValues<T> { | |
fn extend_values<I>(&mut self, iter: I) | |
where | |
I: Iterator<Item = T>; | |
} | |
impl<K, V, E, T> ExtendValues<(K, E)> for HashMap<K, V> | |
where | |
K: Eq + std::hash::Hash, | |
V: Default + Extend<T>, | |
E: IntoIterator<Item = T>, | |
{ | |
fn extend_values<I>(&mut self, iter: I) | |
where | |
I: IntoIterator<Item = (K, E)>, | |
{ | |
for (k, e) in iter { | |
self.entry(k).or_default().extend(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment