diff --git a/src/grouping_map.rs b/src/grouping_map.rs index 8799c6ecb..aeb86f1b2 100644 --- a/src/grouping_map.rs +++ b/src/grouping_map.rs @@ -138,7 +138,7 @@ where /// /// let lookup = (1..=7) /// .into_grouping_map_by(|&n| n % 3) - /// .fold_with(|_key| Default::default(), |Accumulator { acc }, _key, val| { + /// .fold_with(|_key, _val| Default::default(), |Accumulator { acc }, _key, val| { /// let acc = acc + val; /// Accumulator { acc } /// }); @@ -150,11 +150,11 @@ where /// ``` pub fn fold_with(self, mut init: FI, mut operation: FO) -> HashMap where - FI: FnMut(&K) -> R, + FI: FnMut(&K, &V) -> R, FO: FnMut(R, &K, V) -> R, { self.aggregate(|acc, key, val| { - let acc = acc.unwrap_or_else(|| init(key)); + let acc = acc.unwrap_or_else(|| init(key, &val)); Some(operation(acc, key, val)) }) } @@ -189,7 +189,7 @@ where R: Clone, FO: FnMut(R, &K, V) -> R, { - self.fold_with(|_: &K| init.clone(), operation) + self.fold_with(|_, _| init.clone(), operation) } /// Groups elements from the `GroupingMap` source by key and applies `operation` to the elements diff --git a/tests/quick.rs b/tests/quick.rs index d65e274f3..6f45a63d0 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1481,7 +1481,7 @@ quickcheck! { let modulo = if modulo == 0 { 1 } else { modulo } as u64; // Avoid `% 0` let lookup = a.iter().map(|&b| b as u64) // Avoid overflows .into_grouping_map_by(|i| i % modulo) - .fold_with(|_key| Default::default(), |Accumulator { acc }, &key, val| { + .fold_with(|_key, _val| Default::default(), |Accumulator { acc }, &key, val| { assert!(val % modulo == key); let acc = acc + val; Accumulator { acc }