Crate grouping_by[][src]

Expand description

This library provides users the possibility of grouping your iterators of various ways. It is similar to Java Collectors.groupingBy

It is implemented for any type which implements Iterator, but you can implement it to your custom iterator.

Example:

use std::collections::HashMap;
use crate::grouping_by::GroupingBy;

#[derive(Debug, PartialEq)]
struct Point {
   x: i32,
   y: i32,
}
let array: [Point; 4] = [
       Point { x: 1, y: 2 },
       Point { x: 1, y: 3 },
       Point { x: 2, y: 2 },
       Point { x: 2, y: 2 },
];

assert_eq!(
    [
        (1, vec![&Point { x: 1, y: 2 }, &Point { x: 1, y: 3 }]),
        (2, vec![&Point { x: 2, y: 2 }, &Point { x: 2, y: 2 }])
    ]
    .iter()
    .cloned()
    .collect::<HashMap<i32, Vec<&Point>>>(),
    array.iter().grouping_by(|point| point.x)
);

Traits