Skip to content

Commit

Permalink
New GroupingMap::product_in
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Mar 15, 2024
1 parent 8b4de1f commit 5455078
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/grouping_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ where
where
V: Mul<V, Output = V>,
{
self.reduce(|acc, _, val| acc * val)
self.product_in(HashMap::new())
}
}

Expand Down Expand Up @@ -786,4 +786,14 @@ where
{
self.reduce_in(|acc, _, val| acc + val, map)
}

/// Apply [`product`](Self::product) with a provided empty map
/// (`BTreeMap` or `HashMap` with any hasher).
pub fn product_in<M>(self, map: M) -> M
where
V: Mul<V, Output = V>,
M: Map<Key = K, Value = V>,
{
self.reduce_in(|acc, _, val| acc * val, map)
}
}

0 comments on commit 5455078

Please sign in to comment.