Groupable

Trait Groupable 

Source
pub trait Groupable<K, V> {
    // Required method
    fn group<B: FromKeyedIterator<K, V>>(&mut self) -> B;
}
Expand description

Conversion from an Iterator of pairs.

Required Methods§

Source

fn group<B: FromKeyedIterator<K, V>>(&mut self) -> B

Loops through the entire iterator, grouping all keys into a container implementing FromKeyedIterator with a container of values per key. The values will be aggregated per key into a container implementing Extend for the value type.

§Example
use std::collections::HashMap;
use groupable::Groupable;

let evens = (0..10).map(|i| (i % 2 == 0, i))
                   .group::<HashMap<bool, Vec<usize>>>();

assert_eq!(evens[&true], [0, 2, 4, 6, 8]);
assert_eq!(evens[&false], [1, 3, 5, 7, 9]);

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<K, V, I: Iterator<Item = (K, V)>> Groupable<K, V> for I