HasValue

com.phasmidsoftware.number.core.numerical.HasValue
See theHasValue companion object
trait HasValue[T] extends Fractional[T]

Type class trait HasValue[T].

This is used to represent quantities of different underlying units/dimensions.

Type parameters

T

the underlying type of this HasValue.

Attributes

Companion
object
Graph
Supertypes
trait Fractional[T]
trait Numeric[T]
trait Ordering[T]
trait PartialOrdering[T]
trait Equiv[T]
trait Serializable
trait Comparator[T]
class Object
trait Matchable
class Any
Show all
Known subtypes

Members list

Type members

Inherited classlikes

class FractionalOps(lhs: Fractional.this.T) extends NumericOps

Attributes

Inherited from:
Fractional
Supertypes
class Fractional.this.NumericOps
class Object
trait Matchable
class Any
class NumericOps(lhs: Numeric.this.T)

Attributes

Inherited from:
Numeric
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Fractional.this.FractionalOps
class OrderingOps(lhs: Ordering.this.T)

This inner class defines comparison operators available for T.

This inner class defines comparison operators available for T.

It can't extend AnyVal because it is not a top-level class or a member of a statically accessible object.

Value parameters

lhs

the left-hand side value for infix comparison operations

Attributes

Inherited from:
Ordering
Supertypes
class Object
trait Matchable
class Any

Value members

Abstract methods

def fromDouble(x: Double): T

Method to yield a T from a Double.

Method to yield a T from a Double.

Value parameters

x

a Double.

Attributes

Returns

the corresponding value of T.

def normalize(x: T): T

Method to yield a "normalized" version of x. For a Numeric object, this implies the absolute value, i.e., with no sign.

Method to yield a "normalized" version of x. For a Numeric object, this implies the absolute value, i.e., with no sign.

Value parameters

x

the value.

Attributes

Returns

the value, without any sign.

def render(t: T): String

Method to return a String representation of a T value.

Method to return a String representation of a T value.

Value parameters

t

a T value.

Attributes

Returns

the corresponding String.

def scale(t: T, f: Double): T

Method to scale a T value, according to a constant.

Method to scale a T value, according to a constant.

This is essentially the inverse of the ratio method.

Value parameters

f

a factor (a Double, i.e., dimensionless).

t

a T value.

Attributes

Returns

a scaled value of T.

Concrete methods

def multiply[U : HasValue, V : HasValue](u: U, v: V): T

Method to multiply a U by a V, resulting in a T.

Method to multiply a U by a V, resulting in a T.

Type parameters

U

the type of u.

V

the type of v.

Value parameters

u

a U value.

v

a V value.

Attributes

Returns

a T whose value is u * v.

Inherited methods

def abs(x: T): T

Attributes

Inherited from:
Numeric
override def equiv(x: T, y: T): Boolean

Returns true if x == y in the ordering.

Returns true if x == y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering -> Equiv
Inherited from:
Ordering
override def gt(x: T, y: T): Boolean

Returns true if x > y in the ordering.

Returns true if x > y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
override def gteq(x: T, y: T): Boolean

Returns true if x >= y in the ordering.

Returns true if x >= y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def isReverseOf(other: Ordering[_]): Boolean

Returns whether or not the other ordering is the opposite ordering of this one.

Returns whether or not the other ordering is the opposite ordering of this one.

Equivalent to other == this.reverse.

Implementations should only override this method if they are overriding reverse as well.

Value parameters

other

the ordering to check

Attributes

Returns

true if other is the reverse of this ordering, false otherwise

Inherited from:
Ordering
override def lt(x: T, y: T): Boolean

Returns true if x < y in the ordering.

Returns true if x < y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
override def lteq(x: T, y: T): Boolean

Returns true if x <= y in the ordering.

Returns true if x <= y in the ordering.

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def max[U <: T](x: U, y: U): U

Returns x if x >= y, otherwise y.

Returns x if x >= y, otherwise y.

Type parameters

U

a subtype of T, used to preserve the specific type in the return value

Value parameters

x

the first candidate value

y

the second candidate value

Attributes

Inherited from:
Ordering
def min[U <: T](x: U, y: U): U

Returns x if x <= y, otherwise y.

Returns x if x <= y, otherwise y.

Type parameters

U

a subtype of T, used to preserve the specific type in the return value

Value parameters

x

the first candidate value

y

the second candidate value

Attributes

Inherited from:
Ordering
def on[U](f: U => T): Ordering[U]

Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:

Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:

def compare[U, T: Ordering](x: U, y: U, f: U => T) = Ordering[T].compare(f(x), f(y))

Type parameters

U

the type of the values to be ordered

Value parameters

f

the function to extract a T value from a U value

Attributes

Returns

an Ordering[U] that orders values by applying f and comparing the results using this ordering

Inherited from:
Ordering
def one: T

Attributes

Inherited from:
Numeric
def orElse(other: Ordering[T]): Ordering[T]

Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.

Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.

Value parameters

other

an Ordering to use if this Ordering returns zero

Attributes

Returns

an Ordering[T] that uses this ordering first, falling back to other when values are equal

Example
case class Pair(a: Int, b: Int)
val pairOrdering = Ordering.by[Pair, Int](_.a)
                          .orElse(Ordering.by[Pair, Int](_.b))
Inherited from:
Ordering
def orElseBy[S](f: T => S)(implicit ord: Ordering[S]): Ordering[T]

Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:

Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:

def compare[T, S: Ordering](x: T, y: T, f: T => S) = Ordering[S].compare(f(x), f(y))

This function is equivalent to passing the result of Ordering.by(f) to orElse.

Type parameters

S

the type returned by the extraction function f

Value parameters

f

the function to extract a comparison key from a T value

ord

the implicit ordering for the extracted key type S

Attributes

Returns

an Ordering[T] that uses this ordering first, falling back to comparing by f when values are equal

Example
case class Pair(a: Int, b: Int)
val pairOrdering = Ordering.by[Pair, Int](_.a)
                          .orElseBy[Int](_.b)
Inherited from:
Ordering
override def reverse: Ordering[T]

Returns the opposite ordering of this one.

Returns the opposite ordering of this one.

Implementations overriding this method MUST override isReverseOf as well if they change the behavior at all (for example, caching does not require overriding it).

Attributes

Returns

an Ordering[T] that compares elements in the reverse order of this ordering

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def reversed(): Comparator[T]

Attributes

Inherited from:
Comparator
def sign(x: T): T

Attributes

Inherited from:
Numeric
def thenComparing[U <: Comparable[_ >: U <: <FromJavaObject>]](x$0: Function[_ >: T <: <FromJavaObject>, _ <: U]): Comparator[T]

Attributes

Inherited from:
Comparator
def thenComparing[U <: <FromJavaObject>](x$0: Function[_ >: T <: <FromJavaObject>, _ <: U], x$1: Comparator[_ >: U <: <FromJavaObject>]): Comparator[T]

Attributes

Inherited from:
Comparator
def thenComparing(x$0: Comparator[_ >: T <: <FromJavaObject>]): Comparator[T]

Attributes

Inherited from:
Comparator
def thenComparingDouble(x$0: ToDoubleFunction[_ >: T <: <FromJavaObject>]): Comparator[T]

Attributes

Inherited from:
Comparator
def thenComparingInt(x$0: ToIntFunction[_ >: T <: <FromJavaObject>]): Comparator[T]

Attributes

Inherited from:
Comparator
def thenComparingLong(x$0: ToLongFunction[_ >: T <: <FromJavaObject>]): Comparator[T]

Attributes

Inherited from:
Comparator
def tryCompare(x: T, y: T): Some[Int]

Returns whether a comparison between x and y is defined, and if so the result of compare(x, y).

Returns whether a comparison between x and y is defined, and if so the result of compare(x, y).

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Inherited from:
Ordering
def zero: T

Attributes

Inherited from:
Numeric

Inherited and Abstract methods

def compare(x: T, y: T): Int

Returns an integer whose sign communicates how x compares to y.

Returns an integer whose sign communicates how x compares to y.

The result sign has the following meaning:

  • negative if x < y
  • positive if x > y
  • zero otherwise (if x == y)

Value parameters

x

the first value to compare

y

the second value to compare

Attributes

Returns

a negative integer, zero, or a positive integer as x is less than, equal to, or greater than y

Inherited from:
Ordering
def div(x: T, y: T): T

Attributes

Inherited from:
Fractional
def fromInt(x: Int): T

Attributes

Inherited from:
Numeric
def minus(x: T, y: T): T

Attributes

Inherited from:
Numeric
def negate(x: T): T

Attributes

Inherited from:
Numeric
def parseString(str: String): Option[T]

Attributes

Inherited from:
Numeric
def plus(x: T, y: T): T

Attributes

Inherited from:
Numeric
def times(x: T, y: T): T

Attributes

Inherited from:
Numeric
def toDouble(x: T): Double

Attributes

Inherited from:
Numeric
def toFloat(x: T): Float

Attributes

Inherited from:
Numeric
def toInt(x: T): Int

Attributes

Inherited from:
Numeric
def toLong(x: T): Long

Attributes

Inherited from:
Numeric

Deprecated and Inherited methods

def signum(x: T): Int

Attributes

Deprecated
[Since version 2.13.0] use `sign` method instead
Inherited from:
Numeric

Implicits

Inherited implicits

implicit override def mkNumericOps(lhs: T): FractionalOps

Attributes

Definition Classes
Fractional -> Numeric
Inherited from:
Fractional
implicit def mkOrderingOps(lhs: T): OrderingOps

This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.

This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.

Value parameters

lhs

the value to enrich with ordering operators

Attributes

Inherited from:
Ordering