pub fn split_with_remainder(
total: usize,
max_batch_size: usize,
) -> Result<(usize, Vec<NonZeroUsize>, usize), String>Expand description
Splits a total number into even batches, returning the remainder separately.
This function is similar to even_split, but instead of including the remainder
in the last batch, it returns it as a separate value.
§Arguments
total- The total number to be split.max_batch_size- The maximum allowed size for each batch.
§Returns
A Result containing a tuple with:
- The number of batches.
- A vector of
NonZeroUsizerepresenting the size of each batch. - The remainder.
§Errors
Returns an error if:
- The total is zero.
- The max_batch_size is zero.
§Examples
use batch_maestro::split_with_remainder;
use std::num::NonZeroUsize;
let (num_batches, batch_sizes, remainder) = split_with_remainder(50, 8).unwrap();
assert_eq!(num_batches, 6);
assert_eq!(batch_sizes, vec![NonZeroUsize::new(8).unwrap(); 6]);
assert_eq!(remainder, 2);