Skip to content

core::iter::order functions now take two types of iterators. #14289

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

Merged
merged 1 commit into from
May 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ pub mod order {
use super::Iterator;

/// Compare `a` and `b` for equality using `TotalEq`
pub fn equals<A: TotalEq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn equals<A: TotalEq, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return true,
Expand All @@ -2195,7 +2195,7 @@ pub mod order {
}

/// Order `a` and `b` lexicographically using `TotalOrd`
pub fn cmp<A: TotalOrd, T: Iterator<A>>(mut a: T, mut b: T) -> cmp::Ordering {
pub fn cmp<A: TotalOrd, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> cmp::Ordering {
loop {
match (a.next(), b.next()) {
(None, None) => return cmp::Equal,
Expand All @@ -2210,7 +2210,7 @@ pub mod order {
}

/// Compare `a` and `b` for equality (Using partial equality, `Eq`)
pub fn eq<A: Eq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn eq<A: Eq, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return true,
Expand All @@ -2221,7 +2221,7 @@ pub mod order {
}

/// Compare `a` and `b` for nonequality (Using partial equality, `Eq`)
pub fn ne<A: Eq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn ne<A: Eq, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return false,
Expand All @@ -2232,7 +2232,7 @@ pub mod order {
}

/// Return `a` < `b` lexicographically (Using partial order, `Ord`)
pub fn lt<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn lt<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return false,
Expand All @@ -2244,7 +2244,7 @@ pub mod order {
}

/// Return `a` <= `b` lexicographically (Using partial order, `Ord`)
pub fn le<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn le<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return true,
Expand All @@ -2256,7 +2256,7 @@ pub mod order {
}

/// Return `a` > `b` lexicographically (Using partial order, `Ord`)
pub fn gt<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn gt<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return false,
Expand All @@ -2268,7 +2268,7 @@ pub mod order {
}

/// Return `a` >= `b` lexicographically (Using partial order, `Ord`)
pub fn ge<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
pub fn ge<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return true,
Expand Down Expand Up @@ -2325,6 +2325,16 @@ pub mod order {
assert!(gt(c.iter(), b.iter()) == (c[0] > b[0]));
assert!(ge(c.iter(), b.iter()) == (c[0] >= b[0]));
}

#[test]
fn test_multi_iter() {
use slice::ImmutableVector;
use iter::DoubleEndedIterator;
let xs = [1i,2,3,4];
let ys = [4i,3,2,1];
assert!(eq(xs.iter(), ys.iter().rev()));
assert!(lt(xs.iter(), xs.iter().skip(2)));
}
}

#[cfg(test)]
Expand Down