Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ockajak committed Jul 10, 2024
1 parent db75f4b commit 1fcbfb8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 0 additions & 5 deletions src/extensions/collections/btree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ impl<Key: Ord, Value> Map<Key, Value> for BTreeMap<Key, Value> {
flat_map_pairs(self.iter(), |&x| function(x))
}

#[inline]
fn fold<B>(&self, init: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B {
self.iter().fold(init, function)
}

#[inline]
fn map<L, W>(&self, mut function: impl FnMut((&Key, &Value)) -> (L, W)) -> Self::This<L, W>
where
Expand Down
5 changes: 0 additions & 5 deletions src/extensions/collections/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ impl<Key, Value> Map<Key, Value> for HashMap<Key, Value> {
flat_map_pairs(self.iter(), |&x| function(x))
}

#[inline]
fn fold<B>(&self, init: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B {
self.iter().fold(init, function)
}

#[inline]
fn map<L, W>(&self, mut function: impl FnMut((&Key, &Value)) -> (L, W)) -> Self::This<L, W>
where
Expand Down
11 changes: 8 additions & 3 deletions src/extensions/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ pub trait Map<Key, Value> {
/// ]);
///
/// // the sum of all the elements of the array
/// let sum = a.fold(0, |acc, (&k, &v)| acc + k + v.len());
/// let sum = a.fold(0, |acc, (k, v)| acc + k + v.len());
///
/// assert_eq!(sum, 9);
/// ```
Expand All @@ -839,7 +839,12 @@ pub trait Map<Key, Value> {
/// | 3 | 5 | 3 | c | 9 |
///
/// And so, our final result, `9`.
fn fold<B>(&self, init: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B;
fn fold<B>(self, init: B, function: impl FnMut(B, (Key, Value)) -> B) -> B
where
Self: IntoIterator<Item = (Key, Value)> + Sized,
{
self.into_iter().fold(init, function)
}

/// Creates a map by retaining the values representing the intersection
/// of the original map with another map i.e., the values that are
Expand Down Expand Up @@ -1581,7 +1586,7 @@ pub trait Map<Key, Value> {
///
/// // Which is equivalent to doing it with `fold`:
/// # let a = source.clone();
/// let folded = a.fold((0, 0), |(a, b), (&k, &v)| (a + k, b + v));
/// let folded = a.fold((0, 0), |(a, b), (k, v)| (a + k, b + v));
///
/// assert_eq!(reduced, folded);
/// ```
Expand Down

0 comments on commit 1fcbfb8

Please sign in to comment.