Trait nekolib::traits::usize_group_by::UsizeGroupBy
source · pub trait UsizeGroupBy<V> {
// Required method
fn usize_group_by(self, index: impl FnMut(&V) -> usize) -> Vec<Vec<V>>;
}
Required Methods§
sourcefn usize_group_by(self, index: impl FnMut(&V) -> usize) -> Vec<Vec<V>>
fn usize_group_by(self, index: impl FnMut(&V) -> usize) -> Vec<Vec<V>>
Examples
use nekolib::traits::UsizeGroupBy;
let a = vec![1, 4, 3, -5, -6, 0, 2, -2, 3];
let g = a.iter().copied().usize_group_by(|&ai: &i32| ai.rem_euclid(3) as usize);
assert_eq!(g.len(), 3);
assert_eq!(g[0], [3, -6, 0, 3]);
assert_eq!(g[1], [1, 4, -5, -2]);
assert_eq!(g[2], [2]);