Comparer

com.phasmidsoftware.comparer.Comparer
See theComparer companion trait
object Comparer

Companion object for Comparer. This is where you will find the standard given Comparer instances, which are therefore available without any import.

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Comparer.type

Members list

Value members

Concrete methods

def apply[T, U : Comparer](lenses: T => U*): Comparer[T]

Method to construct a Comparer from a variable-length list of Lenses.

Method to construct a Comparer from a variable-length list of Lenses.

Type parameters

T

the underlying type of all Comparers and the result.

U

the type by which the actual comparisons will be made.

Value parameters

lenses

the Lens functions, which must all be of the same type (T=>U). Note that if you want to have varying types, then use same and :| rather than apply.

Attributes

Returns

a Comparer[T] which applies each Comparer in turn.

def compareAll[T : Comparer](ts1: Iterable[T], ts2: Iterable[T]): Comparison

Method to compare two Iterables such that, if the common prefixes are the same, the "larger" Iterable is considered to be the longer one.

Method to compare two Iterables such that, if the common prefixes are the same, the "larger" Iterable is considered to be the longer one.

Type parameters

T

the underlying type.

Value parameters

ts1

an Iterable[T].

ts2

an Iterable[T].

Attributes

Returns

a Comparison.

def comparePrefixes[T : Comparer](ts1: Iterable[T], ts2: Iterable[T]): Comparison

Method to compare two Iterables such that only the common prefixes are compared.

Method to compare two Iterables such that only the common prefixes are compared.

Type parameters

T

the underlying type.

Value parameters

ts1

an Iterable[T].

ts2

an Iterable[T].

Attributes

Returns

a Comparison.

def comparer[T, P : Comparer](lens: T => P): Comparer[T]

This method creates a Comparer[T] based on a given Comparer[P] and a lens function-- by invoking snap on the Comparer[P] and passing in lens.

This method creates a Comparer[T] based on a given Comparer[P] and a lens function-- by invoking snap on the Comparer[P] and passing in lens.

Type parameters

P

the result type of the lens function.

T

the underlying type of the returned Comparer.

Value parameters

lens

a function which takes a T and returns a P.

Attributes

Returns

a Comparer[T].

def create[T](comparers: Comparer[T]*): Comparer[T]

Method to construct a Comparer from a variable-length list of Comparers.

Method to construct a Comparer from a variable-length list of Comparers.

Type parameters

T

the underlying type of all Comparers and the result.

Value parameters

comparers

the Comparers.

Attributes

Returns

a Comparer[T] which applies each Comparer in turn.

inline def derived[T](using m: Of[T]): Comparer[T]

Method to derive a Comparer, so that you can write, for a case class:

Method to derive a Comparer, so that you can write, for a case class:

 case class Date(year: Int, month: Int, day: Int) derives Comparer

or, for an enum (or a sealed trait):

 enum Suit derives Comparer:
   case Clubs, Diamonds, Hearts, Spades

For a case class (or any other product type), the fields are compared in order, from the first (most significant) to the last (least significant), and each field type must itself have a given Comparer. If you need a different order, then build the Comparer explicitly, using same and :|.

For an enum or a sealed trait (a sum type), values of different cases are compared by the order in which the cases are declared. Values of the same case are compared using that case's given Comparer if it has one, otherwise using a Comparer derived for that case (i.e., by its fields).

Recursive types (such as a tree whose nodes contain trees) are supported.

Type parameters

T

the underlying type of the result.

Value parameters

m

the Mirror of T, supplied by the compiler.

Attributes

Returns

a Comparer[T].

def different[T](less: Boolean): Comparer[T]

A method to construct a Comparer which always evaluates to Different(less).

A method to construct a Comparer which always evaluates to Different(less).

Type parameters

T

the underlying type of the Comparer.

Attributes

Returns

a Comparer[T] which always evaluates to Different(less).

def fromOrdering[T](to: Ordering[T]): Comparer[T]

Method to create a Comparer[T] from an Ordering[T].

Method to create a Comparer[T] from an Ordering[T].

Type parameters

T

the underlying type of to and the result.

Value parameters

to

the Ordering[T] to be converted.

Attributes

Returns

a Comparer[T] which has the same intrinsic behavior as "to".

def same[T]: Comparer[T]

A method to construct a Comparer which always evaluates to Same. This is used, for example, in the apply method following.

A method to construct a Comparer which always evaluates to Same. This is used, for example, in the apply method following.

Type parameters

T

the underlying type of the Comparer.

Attributes

Returns

a Comparer[T] which always evaluates to Same.

Givens

Givens

given bigDecimalComparer: Comparer[BigDecimal]
given bigIntComparer: Comparer[BigInt]
given booleanComparer: Comparer[Boolean]
given byteComparer: Comparer[Byte]
given charComparer: Comparer[Char]
given comparerArray: [T : Comparer] => Comparer[Array[T]]

The Comparer of Array[T] where T is any type that has a given Comparer (see comparerIterable).

The Comparer of Array[T] where T is any type that has a given Comparer (see comparerIterable).

Type parameters

T

the underlying type of the inputs.

Attributes

Returns

a Comparer of Array[T].

given comparerEither: [L, R : Comparer] => Comparer[Either[L, R]]

The Comparer of Either[L,R] where R is any type that has a given Comparer. Note that we arbitrarily evaluate all comparisons involving L to be Same (see comparerOpt).

The Comparer of Either[L,R] where R is any type that has a given Comparer. Note that we arbitrarily evaluate all comparisons involving L to be Same (see comparerOpt).

Type parameters

L

the underlying left-hand type of the inputs.

R

the underlying right-hand type of the inputs (must have a given Comparer).

Attributes

Returns

a Comparer of Either[L,R] which can compare two instances of Either[L,R] and return a Comparison.

given comparerIterable: [T : Comparer] => Comparer[Iterable[T]]

The Comparer of Iterable[T] where T is any type that has a given Comparer. Elements at the head of an iterable are considered more significant than those appearing later; Comparisons are made only through the shortest iterable.

The Comparer of Iterable[T] where T is any type that has a given Comparer. Elements at the head of an iterable are considered more significant than those appearing later; Comparisons are made only through the shortest iterable.

Type parameters

T

the underlying type of the inputs.

Attributes

Returns

a Comparer of Iterable[T] which can compare two instances of Iterable[T] and return a Comparison.

given comparerList: [T : Comparer] => Comparer[List[T]]

The Comparer of List[T] where T is any type that has a given Comparer (see comparerIterable).

The Comparer of List[T] where T is any type that has a given Comparer (see comparerIterable).

Type parameters

T

the underlying type of the inputs.

Attributes

Returns

a Comparer of List[T].

given comparerOpt: [T : Comparer] => Comparer[Option[T]]

The Comparer of Option[T] where T is any type that has a given Comparer. NOTE that we arbitrarily evaluate all comparisons involving None to be Same. NOTE this behavior is NOT the same as when using OptionOrdering[T] defined in Ordering.scala.

The Comparer of Option[T] where T is any type that has a given Comparer. NOTE that we arbitrarily evaluate all comparisons involving None to be Same. NOTE this behavior is NOT the same as when using OptionOrdering[T] defined in Ordering.scala.

Type parameters

T

the underlying type of the inputs.

Attributes

Returns

a Comparer of Option[T] which can compare two instances of Option[T] and return a Comparison.

given comparerSeq: [T : Comparer] => Comparer[Seq[T]]

The Comparer of Seq[T] where T is any type that has a given Comparer (see comparerIterable).

The Comparer of Seq[T] where T is any type that has a given Comparer (see comparerIterable).

Type parameters

T

the underlying type of the inputs.

Attributes

Returns

a Comparer of Seq[T].

given comparerTry: [T : Comparer] => Comparer[Try[T]]

The Comparer of Try[T] where T is any type that has a given Comparer. NOTE that we arbitrarily evaluate all comparisons involving Failure to be Same (see comparerOpt).

The Comparer of Try[T] where T is any type that has a given Comparer. NOTE that we arbitrarily evaluate all comparisons involving Failure to be Same (see comparerOpt).

Type parameters

T

the underlying type of the inputs.

Attributes

Returns

a Comparer of Try[T] which can compare two instances of Try[T] and return a Comparison.

given doubleComparer: Comparer[Double]
given emptyTupleComparer: Comparer[EmptyTuple]

The Comparer for the empty tuple, which ends the recursion of tupleComparer.

The Comparer for the empty tuple, which ends the recursion of tupleComparer.

Attributes

given floatComparer: Comparer[Float]
given intComparer: Comparer[Int]
given longComparer: Comparer[Long]
given shortComparer: Comparer[Short]
given stringComparer: Comparer[String]
given tupleComparer: [H, R <: Tuple] => (=> Comparer[H], => Comparer[R]) => Comparer[H *: R]

The Comparer for a tuple of any size whose elements all have given Comparers. The elements are compared in order, from the first (most significant) to the last (least significant). This also provides the comparison of the fields for derived Comparers.

The Comparer for a tuple of any size whose elements all have given Comparers. The elements are compared in order, from the first (most significant) to the last (least significant). This also provides the comparison of the fields for derived Comparers.

NOTE: hc and rc are by-name so that a recursive type can refer to its own Comparer (which is still being defined).

Type parameters

H

the type of the first element.

R

the type of the tuple of the remaining elements.

Attributes

Returns

a Comparer[H *: R].

given unitComparer: Comparer[Unit]

Following are the Comparer definitions for the common scalar types.

Following are the Comparer definitions for the common scalar types.

Attributes