Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ockajak committed Jul 18, 2024
1 parent bd1192d commit abfb342
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 62 deletions.
16 changes: 8 additions & 8 deletions src/extensions/collectible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
///
/// let a = vec![1, 2, 3];
///
/// let (even, odd) = a.partition(|n| n % 2 == 0);
/// let (even, odd) = a.partition(|&x| x % 2 == 0);
///
/// assert_eq!(even, vec![2]);
/// assert_eq!(odd, vec![1, 3]);
Expand Down Expand Up @@ -998,7 +998,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
///
/// let a = vec![1, 2, 3];
///
/// let (even, odd) = a.partition_map(|n| if n % 2 == 0 { Ok(n + 3) } else { Err(*n) });
/// let (even, odd) = a.partition_map(|&x| if x % 2 == 0 { Ok(x + 3) } else { Err(x) });
///
/// assert_eq!(even, vec![5]);
/// assert_eq!(odd, vec![1, 3]);
Expand All @@ -1025,7 +1025,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
///
/// let a = vec![1, 2, 3];
///
/// let (even, odd) = a.partition_map_to(|n| if n % 2 == 0 { Ok(n + 3) } else { Err(n) });
/// let (even, odd) = a.partition_map_to(|x| if x % 2 == 0 { Ok(x + 3) } else { Err(x) });
///
/// assert_eq!(even, vec![5]);
/// assert_eq!(odd, vec![1, 3]);
Expand Down Expand Up @@ -1095,12 +1095,12 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
/// ```
/// use cantrip::*;
///
/// let a = vec![2, 3, 4];
/// let a = vec![1, 2, 3];
/// let e = Vec::<i32>::new();
///
/// let product = a.product();
///
/// assert_eq!(product, 24);
/// assert_eq!(product, 6);
/// assert_eq!(e.product(), 1);
/// ```
#[inline]
Expand Down Expand Up @@ -1136,15 +1136,15 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
/// # let a_source = vec![1, 2, 3];
/// let a = vec![1, 2, 3];
///
/// let reduced = a.reduce_to(|acc, e| acc + e).unwrap();
/// let reduced = a.reduce_to(|acc, e| acc + e);
///
/// assert_eq!(reduced, 6);
/// assert_eq!(reduced, Some(6));
///
/// // Which is equivalent to doing it with `fold`:
/// # let a = a_source.clone();
/// let folded = a.fold_to(0, |acc, e| acc + e);
///
/// assert_eq!(reduced, folded);
/// assert_eq!(reduced.unwrap(), folded);
/// ```
#[inline]
fn reduce_to(self, function: impl FnMut(Item, Item) -> Item) -> Option<Item>
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/traversable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ pub trait Traversable<Item> {
/// # let a_source = vec![1, 2, 3];
/// let a = vec![1, 2, 3];
///
/// let reduced = a.reduce(|&acc, &e| acc + e).unwrap();
/// let reduced = a.reduce(|&acc, &e| acc + e);
///
/// assert_eq!(reduced, 6);
/// assert_eq!(reduced, Some(6));
///
/// // Which is equivalent to doing it with `fold`:
/// # let a = a_source.clone();
/// let folded = a.fold(0, |acc, &e| acc + e);
///
/// assert_eq!(reduced, folded);
/// assert_eq!(reduced.unwrap(), folded);
/// ```
fn reduce(&self, function: impl FnMut(&Item, &Item) -> Item) -> Option<Item>;

Expand Down
Loading

0 comments on commit abfb342

Please sign in to comment.