Comparison

com.phasmidsoftware.comparer.Comparison
See theComparison companion object
enum Comparison

Enumeration which embodies the result of a three-way comparison.

The problem with the Java style of comparing, which Scala also uses, is that you cannot easily compose comparisons. A typical comparison of two quantities compares the two most significant quantities, then, if the objects appear different, the result is returned; otherwise the result of the comparison of the less significant quantities is returned. This requires saving the value of the first comparison in a (final) variable. But yuck!

Comparisons compose lazily: orElse (and the short-circuit operators) only evaluate their other Comparison when needed. In many situations we use pattern-matching on the Comparison value.

NOTE: also that Comparison is a form of three-valued logic, in which More is true, Less is false and Same is indeterminate. That is the sense of &, |, &&, || and toInt, and of the Kleenean yielded by toKleenean.

NOTE: the cases are exported at the package level, so that they can be referred to simply as Same and Different.

Attributes

Companion
object
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

final case class Different(less: Boolean)

A Comparison which is different.

A Comparison which is different.

Value parameters

less

true or false. By conventions, we yield a true value when we compare a lesser object with a greater object.

Attributes

case Same extends Comparison

Sameness (two objects compare as equal).

Sameness (two objects compare as equal).

Attributes