Class/Object

libra

Quantity

Related Docs: object Quantity | package libra

Permalink

final case class Quantity[A, D <: HList](value: A) extends AnyVal with Product with Serializable

Represents a dimensional quantity

A

the Numeric type of the quantity e.g. Int, Float, Double

D

the dimensions

value

the coefficient

Example:
  1. scala> import spire.implicits._
    scala> import libra.implicits._
    scala> Quantity[Double, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil](5.5) // represents 5.5 m
    scala> res0: Quantity[Double, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(5.5)
Linear Supertypes
Serializable, Serializable, Product, Equals, AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Quantity
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyVal
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Quantity(value: A)

    Permalink

    value

    the coefficient

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. def *[D1 <: HList](q1: Quantity[A, D1])(implicit m: Multiply[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Alias for multiply

    Alias for multiply

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 2.m * 3.m
    res0: Quantity[Int, Term[Length, Metre, Fraction[W.`2`.T, W.`1`.T]] :: HNil] = Quantity(6)
  4. def +[D1 <: HList](q1: Quantity[A, D1])(implicit a: Add[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Alias for add

    Alias for add

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 3.m + 2.m
    res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(5)
  5. def -[D1 <: HList](q1: Quantity[A, D1])(implicit a: Add[Quantity[A, D], Quantity[A, D1]], g: AdditiveGroup[A]): Out

    Permalink

    Alias for subtract

    Alias for subtract

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 3.m - 2.m
    res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(1)
  6. def /[D1 <: HList](q1: Quantity[A, D1])(implicit d: Divide[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Alias for divide

    Alias for divide

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 4.0.m / 2.0.m
    res0: Quantity[Double, HNil] = Quantity(2.0)
  7. def /~[D1 <: HList](q1: Quantity[A, D1])(implicit d: EuclideanDivide[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Alias for quotient

    Alias for quotient

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 5.m /~ 2.m
    res0: Quantity[Int, HNil] = Quantity(2)
  8. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  9. def ^[P <: Singleton with Int](pow: P)(implicit p: Power[Quantity[A, D], P]): Out

    Permalink

    Alias for power

    Alias for power

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import shapeless.syntax.singleton._
    scala> import libra.implicits._
    scala> 2.0.m^(3.narrow)
    res0: Quantity[Double, Term[Length, Metre, Fraction[W.`3`.T, W.`1`.T]] :: HNil] = Quantity(8.0)
  10. def add[D1 <: HList](q1: Quantity[A, D1])(implicit a: Add[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Adds another quantity using the spire AdditiveSemigroup.

    Adds another quantity using the spire AdditiveSemigroup.

    q1

    the quantity to add. This must have the equivalient dimensions.

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 3.m add 2.m
    res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(5)
  11. def as[D1 <: HList](implicit ev: Align[D, D1]): Quantity[A, D1]

    Permalink

    Aligns the dimensions of a quantity.

    Aligns the dimensions of a quantity.

    Two quantities may have the same dimension, but have different parameter orders within their HLists. This reorders the dimensions such that the quantites have the same type. This is useful for algebra typeclasses which expect parameters to have the same type.

    D1

    A dimension with the same parameters but a different parameter order

    scala> import shapeless.{ Witness => W, _ }
    scala> import spire.implicits._
    scala> import libra.implicits._
    scala> type MetreKilogram = Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: Term[Mass, Kilogram, Fraction[W.`1`.T, W.`1`.T]] :: HNil
    scala> type KilogramMetre = Term[Mass, Kilogram, Fraction[W.`1`.T, W.`1`.T]] :: Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] ::  HNil
    scala> val q0: Quantity[Double, MetreKilogram] = Quantity(2.0)
    scala> val q1: Quantity[Double, KilogramMetre] = Quantity(3.0)
    // uses spire's Signed typeclass
    scala> q0 compare q1.as[MetreKilogram]
    res0: Int = -1
  12. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  13. def divide[D1 <: HList](q1: Quantity[A, D1])(implicit d: Divide[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Divides by a quantity

    Divides by a quantity

    q1

    the quantity to divide by

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 4.0.m divide 2.0.m
    res0: Quantity[Double, HNil] = Quantity(2.0)
  14. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  15. def invert()(implicit i: Invert[Quantity[A, D]]): Out

    Permalink

    Raises the quantity to the power of -1

    Raises the quantity to the power of -1

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> val x = 2.0.m
    x: Quantity[Double, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(2.0)
    scala> x.invert
    res2: Quantity[Double, Term[Length, Metre, Fraction[W.`-1`.T, W.`1`.T]] :: HNil] = Quantity(0.5)
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. def multiply[D1 <: HList](q1: Quantity[A, D1])(implicit m: Multiply[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Multiplies by a quantity

    Multiplies by a quantity

    q1

    the quantity to multiply by

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 2.m multiply 3.m
    res0: Quantity[Int, Term[Length, Metre, Fraction[W.`2`.T, W.`1`.T]] :: HNil] = Quantity(6)
  18. def negate()(implicit ev: AdditiveGroup[A]): Quantity[A, D]

    Permalink

    Negates the quantity

    Negates the quantity

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> val x = 2.m
    x: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(2)
    scala> x.negate
    res2: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(-2)
  19. def power[P <: Singleton with Int]()(implicit p: Power[Quantity[A, D], P]): Out

    Permalink

    Raises to a power

    Raises to a power

    P

    the Integer power to raise by

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 2.0.m.power[W.`3`.T]
    res0: Quantity[Double, Term[Length, Metre, Fraction[W.`3`.T, W.`1`.T]] :: HNil] = Quantity(8.0)
  20. def quotient[D1 <: HList](q1: Quantity[A, D1])(implicit d: EuclideanDivide[Quantity[A, D], Quantity[A, D1]]): Out

    Permalink

    Euclidean division by a quantity

    Euclidean division by a quantity

    q1

    the quantity to divide by

    returns

    the quotient of Euclidean division

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 5.m quotient 2.m
    res0: Quantity[Int, HNil] = Quantity(2)
  21. def show()(implicit s: Show[Quantity[A, D]]): String

    Permalink

    The standard index form String

    The standard index form String

    scala> import spire.implicits._
    scala> import libra.implicits._
    scala> 2.m.show
    res0: String = 2 m [L]
  22. def subtract[D1 <: HList](q1: Quantity[A, D1])(implicit a: Add[Quantity[A, D], Quantity[A, D1]], group: AdditiveGroup[A]): Out

    Permalink

    Subtracts another quantity using the spire AdditiveGroup

    Subtracts another quantity using the spire AdditiveGroup

    q1

    the quantity to subtract. This must have the equivalient dimensions.

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 3.m subtract 2.m
    res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(1)
  23. def to[U <: UnitOfMeasure[_]](implicit to: ConvertTo[Quantity[A, D], U]): Out

    Permalink

    Converts a quantity from one unit of measure to another

    Converts a quantity from one unit of measure to another

    U

    The unit of measure to convert to

    scala> import spire.implicits._
    scala> import shapeless.{ Witness => W, _ }
    scala> import libra.implicits._
    scala> 2.0.m.to[Centimetre]
    res0: Quantity[Double, Term[Length, Centimetre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(200.0)
  24. val value: A

    Permalink

    the coefficient

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyVal

Inherited from Any

Ungrouped