| Crates.io | iter_chunks_ext |
| lib.rs | iter_chunks_ext |
| version | 0.1.0 |
| created_at | 2025-07-20 02:54:42.270497+00 |
| updated_at | 2025-07-20 02:54:42.270497+00 |
| description | Iterator extension for grouping items. |
| homepage | |
| repository | https://github.com/nossie531/iter_chunks_ext |
| max_upload_size | |
| id | 1760715 |
| size | 21,010 |
Iterator extension for grouping items.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
This crate provides an iterator extension that supports items grouping.
Note that “Grouping” here is dependent on orders, so it is slightly
different from SQL's GROUP BY effect.
use iter_chunks_ext::prelude::*;
let items = vec![("a", 0), ("a", 1), ("b", 0), ("a", 2)];
let chunks = &mut items.iter().chunks(|x| x.0);
let chunk = &mut chunks.next().unwrap();
assert_eq!(chunk.next(), Some(&("a", 0)));
assert_eq!(chunk.next(), Some(&("a", 1)));
assert_eq!(chunk.next(), None);
let chunk = &mut chunks.next().unwrap();
assert_eq!(chunk.next(), Some(&("b", 0)));
assert_eq!(chunk.next(), None);
let chunk = &mut chunks.next().unwrap();
assert_eq!(chunk.next(), Some(&("a", 2)));
assert_eq!(chunk.next(), None);
let chunk = &mut chunks.next();
assert!(chunk.is_none());
There are many crates that can group items from iterators.
Followings are some of them.
📦 itertools (Extra iterator tools)
chunk_by - Creates an iterator for grouping.📦 grouping_by (Grouping hash map creator)
grouping_by - Creates hash map grouped by key.This crate is characterized by following Pros/Cons.
These Pros/Cons are two sides of the same coin.
😊 Pros
Low memory consumption. No heap memory required.
So this crate can work in core environment.
🤔 Cons
Unlike popular iterator methods, iterators and closures are required additional trait bounds.
Clone trait is required for iterators.Copy trait is required for closures.I feel my approach is natural. But as of 2025, I cannot find same approach.
This makes me little uneasy. So, please check carefully before using.
See CHANGELOG.