equal-parts

Crates.ioequal-parts
lib.rsequal-parts
version1.0.3
created_at2025-09-08 15:04:38.90095+00
updated_at2025-09-18 01:36:11.748134+00
descriptionAn iterator that splits a collection into approximately equal parts.
homepage
repositoryhttps://github.com/amchugh/equal-parts
max_upload_size
id1829380
size45,219
Aidan McHugh (amchugh)

documentation

README

equal-parts

Overview

The equal-parts crate provides the EqualParts trait, which allows you to split slices and vectors into a specified number of approximately equal-sized parts. Approximately means that the difference in size between any two parts is at most one element. When the total number of elements doesn't divide evenly, the larger parts appear first.

Basic Example

use equal_parts::EqualParts;

let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let mut iter = data.equal_parts(4);

assert_eq!(iter.next(), Some([1, 2, 3].as_slice()));  // 3 elements
assert_eq!(iter.next(), Some([4, 5, 6].as_slice()));  // 3 elements
assert_eq!(iter.next(), Some([7, 8].as_slice()));     // 2 elements
assert_eq!(iter.next(), Some([9, 10].as_slice()));    // 2 elements
assert_eq!(iter.next(), None);

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

Commit count: 13

cargo fmt