com.phasmidsoftware.comparer
Members list
Type members
Classlikes
Companion object for Comparer. This is where you will find the standard given Comparer instances, which are therefore available without any import.
Type class trait Comparer[T].
Type class trait Comparer[T].
The behavior of this trait is that it is a lazy comparer of two T instances, presented as two curried parameters, the inner (first) and the outer (second). In all (curried) comparisons, the outer instance is compared with the inner instance. The result of the comparison is a Comparison object.
This class extends the function T => T => Comparison, i.e., a curried function. This is more appropriate here because the two T values being compared are not related in any way--they do not form part of something. Furthermore, using a curried function allows us to yield a partially applied function, which is a closure on just one of the comparands.
A Comparer for a case class can be derived, comparing the fields in order from most to least significant:
case class Date(year: Int, month: Int, day: Int) derives Comparer
Type parameters
- T
-
the underlying type of the comparer. That's to say the type this Comparer knows about.
Attributes
- Companion
- object
- Supertypes
Enumeration which embodies the result of a three-way 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
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Companion object for Comparison.
Companion object for Comparison.
Attributes
- Companion
- enum
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
Comparison.type
Enumeration which models a three-valued logic based on the algebra of Stephen C. Kleene. See https://en.wikipedia.org/wiki/Three-valued_logic
Enumeration which models a three-valued logic based on the algebra of Stephen C. Kleene. See https://en.wikipedia.org/wiki/Three-valued_logic
A Kleenean can be converted to an Option[Boolean] when required (see toOption).
NOTE: the cases are exported at the package level, so that they can be referred to simply as Maybe and Truth.
Attributes
- Companion
- object
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Exports
Defined exports
Different(true).
Different(true).
Attributes
Different(false).
Different(false).