equal-parts 1.0.1

An iterator that splits a collection into approximately equal parts.
Documentation
  • Coverage
  • 83.33%
    5 out of 6 items documented3 out of 3 items with examples
  • Size
  • Source code size: 8.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.14 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • amchugh/equal-parts
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • amchugh

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.