Crates.io | iter-group |
lib.rs | iter-group |
version | 0.3.0 |
source | src |
created_at | 2022-09-01 13:17:43.726526 |
updated_at | 2024-08-08 15:01:21.205318 |
description | Library for grouping (key,value) iterators into maps of collections |
homepage | https://github.com/tuffy/iter-group |
repository | https://github.com/tuffy/iter-group |
max_upload_size | |
id | 656688 |
size | 13,052 |
A trivial library to extend (key, value)
iterators with a method
that returns a mapping type whose keys are grouped into some
collection of type value
.
Essentially, it replaces this:
let a = [(1, 'a'), (2, 'b'), (3, 'c'), (2, 'd'), (1, 'e'), (1, 'f')];
let mut map: HashMap<_, Vec<_>> = HashMap::default();
for (k, v) in a.into_iter() {
map.entry(k).or_default().push(v);
}
with this:
use iter_group:::IntoGroup;
let a = [(1, 'a'), (2, 'b'), (3, 'c'), (2, 'd'), (1, 'e'), (1, 'f')];
let map = a.into_iter().group::<HashMap<_, Vec<_>>>();
See the documentation for additional examples.