Rename ordering chaining functions.

This commit is contained in:
Marcin Fatyga 2016-10-27 23:31:10 +02:00
parent 634715a736
commit 4e2822c5c2
2 changed files with 32 additions and 32 deletions

View File

@ -256,26 +256,26 @@ impl Ordering {
///
/// use std::cmp::Ordering;
///
/// let result = Ordering::Equal.or(Ordering::Less);
/// let result = Ordering::Equal.then(Ordering::Less);
/// assert_eq!(result, Ordering::Less);
///
/// let result = Ordering::Less.or(Ordering::Equal);
/// let result = Ordering::Less.then(Ordering::Equal);
/// assert_eq!(result, Ordering::Less);
///
/// let result = Ordering::Less.or(Ordering::Greater);
/// let result = Ordering::Less.then(Ordering::Greater);
/// assert_eq!(result, Ordering::Less);
///
/// let result = Ordering::Equal.or(Ordering::Equal);
/// let result = Ordering::Equal.then(Ordering::Equal);
/// assert_eq!(result, Ordering::Equal);
///
/// let x: (i64, i64, i64) = (1, 2, 7);
/// let y: (i64, i64, i64) = (1, 5, 3);
/// let result = x.0.cmp(&y.0).or(x.1.cmp(&y.1)).or(x.2.cmp(&y.2));
/// let result = x.0.cmp(&y.0).then(x.1.cmp(&y.1)).then(x.2.cmp(&y.2));
///
/// assert_eq!(result, Ordering::Less);
/// ```
#[unstable(feature = "ordering_chaining", issue = "37053")]
pub fn or(self, other: Ordering) -> Ordering {
pub fn then(self, other: Ordering) -> Ordering {
match self {
Equal => other,
_ => self,
@ -294,26 +294,26 @@ impl Ordering {
///
/// use std::cmp::Ordering;
///
/// let result = Ordering::Equal.or_else(|| Ordering::Less);
/// let result = Ordering::Equal.then_with(|| Ordering::Less);
/// assert_eq!(result, Ordering::Less);
///
/// let result = Ordering::Less.or_else(|| Ordering::Equal);
/// let result = Ordering::Less.then_with(|| Ordering::Equal);
/// assert_eq!(result, Ordering::Less);
///
/// let result = Ordering::Less.or_else(|| Ordering::Greater);
/// let result = Ordering::Less.then_with(|| Ordering::Greater);
/// assert_eq!(result, Ordering::Less);
///
/// let result = Ordering::Equal.or_else(|| Ordering::Equal);
/// let result = Ordering::Equal.then_with(|| Ordering::Equal);
/// assert_eq!(result, Ordering::Equal);
///
/// let x: (i64, i64, i64) = (1, 2, 7);
/// let y: (i64, i64, i64) = (1, 5, 3);
/// let result = x.0.cmp(&y.0).or_else(|| x.1.cmp(&y.1)).or_else(|| x.2.cmp(&y.2));
/// let result = x.0.cmp(&y.0).then_with(|| x.1.cmp(&y.1)).then_with(|| x.2.cmp(&y.2));
///
/// assert_eq!(result, Ordering::Less);
/// ```
#[unstable(feature = "ordering_chaining", issue = "37053")]
pub fn or_else<F: FnOnce() -> Ordering>(self, f: F) -> Ordering {
pub fn then_with<F: FnOnce() -> Ordering>(self, f: F) -> Ordering {
match self {
Equal => f(),
_ => self,

View File

@ -42,29 +42,29 @@ fn test_ordering_order() {
}
#[test]
fn test_ordering_or() {
assert_eq!(Equal.or(Less), Less);
assert_eq!(Equal.or(Equal), Equal);
assert_eq!(Equal.or(Greater), Greater);
assert_eq!(Less.or(Less), Less);
assert_eq!(Less.or(Equal), Less);
assert_eq!(Less.or(Greater), Less);
assert_eq!(Greater.or(Less), Greater);
assert_eq!(Greater.or(Equal), Greater);
assert_eq!(Greater.or(Greater), Greater);
fn test_ordering_then() {
assert_eq!(Equal.then(Less), Less);
assert_eq!(Equal.then(Equal), Equal);
assert_eq!(Equal.then(Greater), Greater);
assert_eq!(Less.then(Less), Less);
assert_eq!(Less.then(Equal), Less);
assert_eq!(Less.then(Greater), Less);
assert_eq!(Greater.then(Less), Greater);
assert_eq!(Greater.then(Equal), Greater);
assert_eq!(Greater.then(Greater), Greater);
}
#[test]
fn test_ordering_or_else() {
assert_eq!(Equal.or_else(|| Less), Less);
assert_eq!(Equal.or_else(|| Equal), Equal);
assert_eq!(Equal.or_else(|| Greater), Greater);
assert_eq!(Less.or_else(|| Less), Less);
assert_eq!(Less.or_else(|| Equal), Less);
assert_eq!(Less.or_else(|| Greater), Less);
assert_eq!(Greater.or_else(|| Less), Greater);
assert_eq!(Greater.or_else(|| Equal), Greater);
assert_eq!(Greater.or_else(|| Greater), Greater);
fn test_ordering_then_with() {
assert_eq!(Equal.then_with(|| Less), Less);
assert_eq!(Equal.then_with(|| Equal), Equal);
assert_eq!(Equal.then_with(|| Greater), Greater);
assert_eq!(Less.then_with(|| Less), Less);
assert_eq!(Less.then_with(|| Equal), Less);
assert_eq!(Less.then_with(|| Greater), Less);
assert_eq!(Greater.then_with(|| Less), Greater);
assert_eq!(Greater.then_with(|| Equal), Greater);
assert_eq!(Greater.then_with(|| Greater), Greater);
}
#[test]