cmp_by

Function cmp_by 

Source
pub fn cmp_by<T, L, R, F>(a: L, b: R, cmp: F) -> Option<Ordering>
where L: IntoIterator<Item = T>, R: IntoIterator<Item = T>, F: FnMut(&mut T, &mut T) -> Ordering,
Expand description

Compare two sets represented by sorted, deduplicated iterators, using a comparator function.

See cmp().

ยงExamples

Using a custom comparator to reverse the ordering

use std::cmp::Ordering::{Equal, Greater, Less};
use iter_set::cmp_by;

let a = [3, 2, 1];
let b = [3, 2];
let c = [4, 3, 2];

assert_eq!(cmp_by(&a, &b, |l, r| Ord::cmp(r, l)), Some(Greater));
assert_eq!(cmp_by(&b, &b, |l, r| Ord::cmp(r, l)), Some(Equal));
assert_eq!(cmp_by(&b, &c, |l, r| Ord::cmp(r, l)), Some(Less));
assert_eq!(cmp_by(&a, &c, |l, r| Ord::cmp(r, l)), None);