diff --git a/src/unique_impl.rs b/src/unique_impl.rs index 0f6397e48..6ecc6e0ce 100644 --- a/src/unique_impl.rs +++ b/src/unique_impl.rs @@ -116,6 +116,23 @@ where }) } + fn fold(mut self, init: B, mut f: F) -> B + where + Self: Sized, + F: FnMut(B, Self::Item) -> B, + { + let UniqueBy { iter, used, .. } = &mut self.iter; + iter.fold(init, |mut acc, v| { + if let Entry::Vacant(e) = used.entry(v) { + let elt = e.key().clone(); + e.insert(()); + acc = f(acc, elt); + } + + acc + }) + } + #[inline] fn size_hint(&self) -> (usize, Option) { let (low, hi) = self.iter.iter.size_hint();