Closed
Description
This seems like an obvious and missing function from std::cmp::Ordering
:
impl Ordering {
pub fn then(self, other: Ordering) -> Ordering {
match self {
Ordering::Equal => other,
o => o,
}
}
pub fn and_then<F: FnOnce() -> Ordering>(self, other: F) -> Ordering {
match self {
Ordering::Equal => other(),
o => o,
}
}
}
This is useful for creating comparators which do lexicographic order. The second variant allows for skipping the order calculation if it is not necessary. Names are of course open to bikeshedding.