Skip to main content

UsizeGroupBy

Trait UsizeGroupBy 

Source
pub trait UsizeGroupBy<V> {
    // Required method
    fn usize_group_by(self, index: impl FnMut(&V) -> usize) -> Vec<Vec<V>>;
}
Expand description

イテレータのグルーピング。

§See also

GroupBy

Required Methods§

Source

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]);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<V, I: Iterator<Item = V>> UsizeGroupBy<V> for I