Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonicalize free functions #591

Merged
merged 7 commits into from
Mar 11, 2022
4 changes: 1 addition & 3 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ pub struct Interleave<I, J> {

/// Create an iterator that interleaves elements in `i` and `j`.
///
/// [`IntoIterator`] enabled version of `i.interleave(j)`.
///
/// See [`.interleave()`](crate::Itertools::interleave) for more information.
/// [`IntoIterator`] enabled version of `[Itertools::interleave]`.
pub fn interleave<I, J>(i: I, j: J) -> Interleave<<I as IntoIterator>::IntoIter, <J as IntoIterator>::IntoIter>
where I: IntoIterator,
J: IntoIterator<Item = I::Item>
Expand Down
4 changes: 2 additions & 2 deletions src/kmerge_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<T, F: FnMut(&T, &T)->bool> KMergePredicate<T> for F {
/// Create an iterator that merges elements of the contained iterators using
/// the ordering function.
///
/// Equivalent to `iterable.into_iter().kmerge()`.
/// [`IntoIterator`] enabled version of [`Itertools::kmerge`].
///
/// ```
/// use itertools::kmerge;
Expand Down Expand Up @@ -170,7 +170,7 @@ impl<I, F> fmt::Debug for KMergeBy<I, F>

/// Create an iterator that merges elements of the contained iterators.
///
/// Equivalent to `iterable.into_iter().kmerge_by(less_than)`.
/// [`IntoIterator`] enabled version of [`Itertools::kmerge_by`].
pub fn kmerge_by<I, F>(iterable: I, mut less_than: F)
-> KMergeBy<<I::Item as IntoIterator>::IntoIter, F>
where I: IntoIterator,
Expand Down
15 changes: 2 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3478,8 +3478,7 @@ impl<T: ?Sized> Itertools for T where T: Iterator { }
/// (elements pairwise equal and sequences of the same length),
/// `false` otherwise.
///
/// This is an [`IntoIterator`] enabled function that is similar to the standard
/// library method [`Iterator::eq`].
/// [`IntoIterator`] enabled version of [`Iterator::eq`].
///
/// ```
/// assert!(itertools::equal(vec![1, 2, 3], 1..4));
Expand All @@ -3490,17 +3489,7 @@ pub fn equal<I, J>(a: I, b: J) -> bool
J: IntoIterator,
I::Item: PartialEq<J::Item>
{
let mut ia = a.into_iter();
let mut ib = b.into_iter();
loop {
match ia.next() {
Some(x) => match ib.next() {
Some(y) => if x != y { return false; },
None => return false,
},
None => return ib.next().is_none()
}
}
a.into_iter().eq(b)
}

/// Assert that two iterables produce equal sequences, with the same
Expand Down
4 changes: 3 additions & 1 deletion src/merge_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use std::fmt;

use super::adaptors::{PutBack, put_back};
use crate::either_or_both::EitherOrBoth;
#[cfg(doc)]
use crate::Itertools;

/// Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.
///
/// See [`.merge_join_by()`](crate::Itertools::merge_join_by) for more information.
/// [`IntoIterator`] enabled version of [`Itertools::merge_join_by`].
pub fn merge_join_by<I, J, F>(left: I, right: J, cmp_fn: F)
-> MergeJoinBy<I::IntoIter, J::IntoIter, F>
where I: IntoIterator,
Expand Down
4 changes: 4 additions & 0 deletions src/multipeek_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::iter::Fuse;
use alloc::collections::VecDeque;
use crate::size_hint;
use crate::PeekingNext;
#[cfg(doc)]
use crate::Itertools;

/// See [`multipeek()`] for more information.
#[derive(Clone, Debug)]
Expand All @@ -15,6 +17,8 @@ pub struct MultiPeek<I>

/// An iterator adaptor that allows the user to peek at multiple `.next()`
/// values without advancing the base iterator.
///
/// [`IntoIterator`] enabled version of [`Itertools::multipeek`].
pub fn multipeek<I>(iterable: I) -> MultiPeek<I::IntoIter>
where I: IntoIterator
{
Expand Down