Skip to content

Commit 943494c

Browse files
bors[bot]phimuemue
andauthored
Merge #591
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>
2 parents 6c4fc2f + 8e73e5d commit 943494c

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

src/adaptors/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ pub struct Interleave<I, J> {
3535

3636
/// Create an iterator that interleaves elements in `i` and `j`.
3737
///
38-
/// [`IntoIterator`] enabled version of `i.interleave(j)`.
39-
///
40-
/// See [`.interleave()`](crate::Itertools::interleave) for more information.
38+
/// [`IntoIterator`] enabled version of `[Itertools::interleave]`.
4139
pub fn interleave<I, J>(i: I, j: J) -> Interleave<<I as IntoIterator>::IntoIter, <J as IntoIterator>::IntoIter>
4240
where I: IntoIterator,
4341
J: IntoIterator<Item = I::Item>

src/kmerge_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<T, F: FnMut(&T, &T)->bool> KMergePredicate<T> for F {
129129
/// Create an iterator that merges elements of the contained iterators using
130130
/// the ordering function.
131131
///
132-
/// Equivalent to `iterable.into_iter().kmerge()`.
132+
/// [`IntoIterator`] enabled version of [`Itertools::kmerge`].
133133
///
134134
/// ```
135135
/// use itertools::kmerge;
@@ -170,7 +170,7 @@ impl<I, F> fmt::Debug for KMergeBy<I, F>
170170

171171
/// Create an iterator that merges elements of the contained iterators.
172172
///
173-
/// Equivalent to `iterable.into_iter().kmerge_by(less_than)`.
173+
/// [`IntoIterator`] enabled version of [`Itertools::kmerge_by`].
174174
pub fn kmerge_by<I, F>(iterable: I, mut less_than: F)
175175
-> KMergeBy<<I::Item as IntoIterator>::IntoIter, F>
176176
where I: IntoIterator,

src/lib.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,8 +3478,7 @@ impl<T: ?Sized> Itertools for T where T: Iterator { }
34783478
/// (elements pairwise equal and sequences of the same length),
34793479
/// `false` otherwise.
34803480
///
3481-
/// This is an [`IntoIterator`] enabled function that is similar to the standard
3482-
/// library method [`Iterator::eq`].
3481+
/// [`IntoIterator`] enabled version of [`Iterator::eq`].
34833482
///
34843483
/// ```
34853484
/// assert!(itertools::equal(vec![1, 2, 3], 1..4));
@@ -3490,17 +3489,7 @@ pub fn equal<I, J>(a: I, b: J) -> bool
34903489
J: IntoIterator,
34913490
I::Item: PartialEq<J::Item>
34923491
{
3493-
let mut ia = a.into_iter();
3494-
let mut ib = b.into_iter();
3495-
loop {
3496-
match ia.next() {
3497-
Some(x) => match ib.next() {
3498-
Some(y) => if x != y { return false; },
3499-
None => return false,
3500-
},
3501-
None => return ib.next().is_none()
3502-
}
3503-
}
3492+
a.into_iter().eq(b)
35043493
}
35053494

35063495
/// Assert that two iterables produce equal sequences, with the same

src/merge_join.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ use std::fmt;
44

55
use super::adaptors::{PutBack, put_back};
66
use crate::either_or_both::EitherOrBoth;
7+
#[cfg(doc)]
8+
use crate::Itertools;
79

810
/// Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.
911
///
10-
/// See [`.merge_join_by()`](crate::Itertools::merge_join_by) for more information.
12+
/// [`IntoIterator`] enabled version of [`Itertools::merge_join_by`].
1113
pub fn merge_join_by<I, J, F>(left: I, right: J, cmp_fn: F)
1214
-> MergeJoinBy<I::IntoIter, J::IntoIter, F>
1315
where I: IntoIterator,

src/multipeek_impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::iter::Fuse;
22
use alloc::collections::VecDeque;
33
use crate::size_hint;
44
use crate::PeekingNext;
5+
#[cfg(doc)]
6+
use crate::Itertools;
57

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

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

0 commit comments

Comments
 (0)