Added doctest for GroupingMap::count
@@ -192,6 +192,27 @@ where
/// Groups elements from the `GroupingMap` source by key and counts them.
///
/// Return a `HashMap` associating the key of each group with the number of elements in that group.
+ ///
+ /// ```
+ /// use itertools::Itertools;
+ ///
+ /// let lookup = "This is a string".chars()
+ /// .map(|c| (c, c))
+ /// .into_grouping_map()
+ /// .count();
+ ///
+ /// assert_eq!(lookup[&'T'], 1);
+ /// assert_eq!(lookup[&'h'], 1);
+ /// assert_eq!(lookup[&'i'], 3);
+ /// assert_eq!(lookup[&'s'], 3);
+ /// assert_eq!(lookup[&' '], 3);
+ /// assert_eq!(lookup[&'a'], 1);
+ /// assert_eq!(lookup[&'t'], 1);
+ /// assert_eq!(lookup[&'r'], 1);
+ /// assert_eq!(lookup[&'n'], 1);
+ /// assert_eq!(lookup[&'g'], 1);
+ /// assert_eq!(lookup.len(), 10);
+ /// ```
pub fn count(self) -> HashMap<K, usize> {
self.fold(0, |acc, _, _| acc + 1)
}
