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 966c0ed commit 280a6d9
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 155 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ data.group_by(|x| x % 2); // HashMap::from([(0, vec![2]), (1, vec![1, 3]
| *intersperse* | :heavy_check_mark: | | | |
| *intersperse_with* | :heavy_check_mark: | | | |
| *init* | :heavy_check_mark: | :heavy_check_mark: | | |
| *join_items* | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| *join_items* | :heavy_check_mark: | :heavy_check_mark: | | |
| *largest* | :heavy_check_mark: | | :heavy_check_mark: | |
| *map* | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: |
| *map_to* | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: |
Expand Down
14 changes: 7 additions & 7 deletions src/extensions/collectible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
/// This is a non-consuming variant of [`flat_map_to`].
///
/// [`map`]: Collectible::map
/// [`flat`]: Collectible::flatten
/// [`flat`]: Collectible::flat
/// [`flat_map_to`]: Collectible::flat_map_to
///
/// # Example
Expand All @@ -506,9 +506,9 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
/// let a = vec![1, 2, 3];
///
/// // Vec is iterable because it implements IntoIterator
/// let flattened = a.flat_map(|&x| vec![x, -x]);
/// let flat_mapped = a.flat_map(|&x| vec![x, -x]);
///
/// assert_eq!(flattened, vec![1, -1, 2, -2, 3, -3]);
/// assert_eq!(flat_mapped, vec![1, -1, 2, -2, 3, -3]);
/// ```
fn flat_map<B, R>(&self, function: impl FnMut(&Item) -> R) -> Self::This<B>
where
Expand All @@ -533,7 +533,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
/// This is a consuming variant of [`flat_map`].
///
/// [`map`]: Collectible::map
/// [`flat`]: Collectible::flatten
/// [`flat`]: Collectible::flat
/// [`flat_map`]: Collectible::flat_map
///
/// # Example
Expand All @@ -544,9 +544,9 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
/// let a = vec![1, 2, 3];
///
/// // Vec is iterable because it implements IntoIterator
/// let flattened = a.flat_map_to(|x| vec![x, -x]);
/// let flat_mapped = a.flat_map_to(|x| vec![x, -x]);
///
/// assert_eq!(flattened, vec![1, -1, 2, -2, 3, -3]);
/// assert_eq!(flat_mapped, vec![1, -1, 2, -2, 3, -3]);
/// ```
#[inline]
fn flat_map_to<B, R>(self, function: impl FnMut(Item) -> R) -> Self::This<B>
Expand Down Expand Up @@ -781,8 +781,8 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
///
/// ```
/// use crate::cantrip::*;
///
/// use std::collections::HashSet;
///
/// let a = vec![1, 2, 3];
/// let e: Vec<i32> = Vec::new();
///
Expand Down
9 changes: 0 additions & 9 deletions src/extensions/collections/binary_heap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cmp::Ordering;
use std::collections::BinaryHeap;
use std::fmt::Display;
use std::hash::Hash;
use crate::extensions::*;

Expand Down Expand Up @@ -30,14 +29,6 @@ impl<Item> Traversable<Item> for BinaryHeap<Item> {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down
10 changes: 0 additions & 10 deletions src/extensions/collections/btree_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::extensions::*;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::fmt::Display;
use std::hash::Hash;

impl<Key: Ord, Value> Map<Key, Value> for BTreeMap<Key, Value> {
Expand Down Expand Up @@ -71,15 +70,6 @@ impl<Key: Ord, Value> Map<Key, Value> for BTreeMap<Key, Value> {
self.iter().fold(init, function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Key: Display,
Value: Display,
{
join_items_pairs(self.iter(), separator)
}

#[inline]
fn map<L, W>(&self, mut function: impl FnMut((&Key, &Value)) -> (L, W)) -> Self::This<L, W>
where
Expand Down
9 changes: 0 additions & 9 deletions src/extensions/collections/btree_set.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::extensions::*;
use std::cmp::Ordering;
use std::collections::BTreeSet;
use std::fmt::Display;
use std::hash::Hash;

impl<Item> Traversable<Item> for BTreeSet<Item> {
Expand Down Expand Up @@ -30,14 +29,6 @@ impl<Item> Traversable<Item> for BTreeSet<Item> {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down
10 changes: 0 additions & 10 deletions src/extensions/collections/hash_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt::Display;
use std::hash::Hash;
use crate::extensions::*;

Expand Down Expand Up @@ -70,15 +69,6 @@ impl<Key, Value> Map<Key, Value> for HashMap<Key, Value> {
self.iter().fold(init, function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Key: Display,
Value: Display,
{
join_items_pairs(self.iter(), separator)
}

#[inline]
fn map<L, W>(&self, mut function: impl FnMut((&Key, &Value)) -> (L, W)) -> Self::This<L, W>
where
Expand Down
9 changes: 0 additions & 9 deletions src/extensions/collections/hash_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cmp::Ordering;
use std::collections::HashSet;
use std::fmt::Display;
use std::hash::Hash;

use crate::extensions::*;
Expand Down Expand Up @@ -31,14 +30,6 @@ impl<Item> Traversable<Item> for HashSet<Item> {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down
16 changes: 8 additions & 8 deletions src/extensions/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ impl<Item> Traversable<Item> for LinkedList<Item> {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down Expand Up @@ -103,6 +95,14 @@ impl<Item> Ordered<Item> for LinkedList<Item> {
includes(self.iter(), iterable)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn position(&self, predicate: impl FnMut(&Item) -> bool) -> Option<usize> {
self.iter().position(predicate)
Expand Down
16 changes: 8 additions & 8 deletions src/extensions/collections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ impl<Item> Traversable<Item> for [Item] {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down Expand Up @@ -103,6 +95,14 @@ impl<Item> Ordered<Item> for [Item] {
includes(self.iter(), iterable)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn position(&self, predicate: impl FnMut(&Item) -> bool) -> Option<usize> {
self.iter().position(predicate)
Expand Down
16 changes: 8 additions & 8 deletions src/extensions/collections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ impl<Item> Traversable<Item> for Vec<Item> {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down Expand Up @@ -102,6 +94,14 @@ impl<Item> Ordered<Item> for Vec<Item> {
includes(self.iter(), iterable)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn position(&self, predicate: impl FnMut(&Item) -> bool) -> Option<usize> {
self.iter().position(predicate)
Expand Down
16 changes: 8 additions & 8 deletions src/extensions/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ impl<Item> Traversable<Item> for VecDeque<Item> {
self.iter().find_map(function)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn max_by(&self, mut compare: impl FnMut(&Item, &Item) -> Ordering) -> Option<&Item> {
self.iter().max_by(|&x, &y| compare(x, y))
Expand Down Expand Up @@ -103,6 +95,14 @@ impl<Item> Ordered<Item> for VecDeque<Item> {
includes(self.iter(), iterable)
}

#[inline]
fn join_items(&self, separator: &str) -> String
where
Item: Display,
{
join_items(self.iter(), separator)
}

#[inline]
fn position(&self, predicate: impl FnMut(&Item) -> bool) -> Option<usize> {
self.iter().position(predicate)
Expand Down
Loading

0 comments on commit 280a6d9

Please sign in to comment.