github.com/enetx/g@v1.0.80/cmp/ordering.go (about) 1 package cmp 2 3 import "fmt" 4 5 // Ordering is the result of a comparison between two values. 6 type Ordering int 7 8 const ( 9 Less Ordering = iota - 1 // Less represents an ordered value where a compared value is less than another. 10 Equal // Equal represents an ordered value where a compared value is equal to another. 11 Greater // Greater represents an ordered value where a compared value is greater than another. 12 ) 13 14 // Then returns the receiver if it's equal to Equal, otherwise returns the receiver. 15 func (o Ordering) Then(other Ordering) Ordering { 16 if o.IsEq() { 17 return other 18 } 19 20 return o 21 } 22 23 // Reverse reverses the ordering. 24 func (o Ordering) Reverse() Ordering { 25 switch o { 26 case Less: 27 return Greater 28 case Greater: 29 return Less 30 default: 31 return Equal 32 } 33 } 34 35 // IsLt returns true if the Ordering value is Less. 36 func (o Ordering) IsLt() bool { return Less == o } 37 38 // IsEq returns true if the Ordering value is Equal. 39 func (o Ordering) IsEq() bool { return Equal == o } 40 41 // IsGt returns true if the Ordering value is Greater. 42 func (o Ordering) IsGt() bool { return Greater == o } 43 44 // String returns the string representation of the Ordering value. 45 func (o Ordering) String() string { 46 switch o { 47 case Less: 48 return "Less" 49 case Equal: 50 return "Equal" 51 case Greater: 52 return "Greater" 53 default: 54 return fmt.Sprintf("Unknown Ordering value: %d", int(o)) 55 } 56 }