Skip to content

Commit

Permalink
Merge #591
Browse files Browse the repository at this point in the history
591: Canonicalize free functions r=jswrenn a=phimuemue

As made visible by #587, I think we should have (somewhat) uniform documentation of free functions.

On top of that, I think `fn equal` should actually use `Iterator::eq` (available since Rust 1.5), instead of only referring to it in the documentation.

Maybe someone finds time to have a look at this, as I'd like to avoid silly mistakes before merging.

Co-authored-by: philipp <descpl@yahoo.de>
  • Loading branch information
bors[bot] and phimuemue committed Mar 11, 2022
2 parents 6c4fc2f + 8e73e5d commit 943494c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/adaptors/mod.rs
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
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
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
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
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

0 comments on commit 943494c

Please sign in to comment.