Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2013 16:47
Show Gist options
  • Save anonymous/17b1b418713e676d5cea to your computer and use it in GitHub Desktop.
Save anonymous/17b1b418713e676d5cea to your computer and use it in GitHub Desktop.
/// Eq
pub fn seq_eq<A: Eq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return true,
(None, _) | (_, None) => return false,
(Some(x), Some(y)) => if !x.eq(&y) { return false },
}
}
}
/// Neq
pub fn seq_ne<A: Eq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return false,
(None, _) | (_, None) => return true,
(Some(x), Some(y)) => if x.ne(&y) { return true },
}
}
}
/// Less Than
pub fn seq_lt<A: Eq + Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return false,
(None, _ ) => return true,
(_ , None) => return false,
(Some(x), Some(y)) => if !x.eq(&y) { return x.lt(&y) },
}
}
}
/// Less Than or Equal
pub fn seq_le<A: Eq + Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
loop {
match (a.next(), b.next()) {
(None, None) => return true,
(None, _ ) => return true,
(_ , None) => return false,
(Some(x), Some(y)) => if !x.eq(&y) { return x.le(&y) },
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment