Base class for creating objects to manage quantities as Numeric.
Base class for creating objects to manage quantities as Numeric.
One limitation is the times
operation which is not supported by every quantity type
Quantity type
SI Base Quantity
Represents a Dimension or Quantity Type
Represents a Dimension or Quantity Type
This trait should be mixed into the Companion Objects of specific Quantity Types.
Quantity Type
Represents a quantity of some thing for which there is no dimension.
Represents a quantity of some thing for which there is no dimension.
This may be used to represent counts or other discrete amounts of everyday life, but may also represent ratios between like quantities where the units have cancelled out.
0.1
Base trait for units of squants.Dimensionless
Base trait for units of squants.Dimensionless
The DimensionlessUnit is a useful paradox
Double (Real Number) Vector
Double (Real Number) Vector
Double*
0.3.0
Identifies the Unit of Measure with a conversionFactor of 1.0.
Identifies the Unit of Measure with a conversionFactor of 1.0.
It is used as the intermediary unit during conversions
Each Quantity should have one and only one ValueUnit
A base class for measurable quantities, instances of which contain a value and a unit
A base class for measurable quantities, instances of which contain a value and a unit
0.1
Represents a Range starting at one Quantity value and going up to another
Represents a Range starting at one Quantity value and going up to another
the Quantity Type
Quantity representing the lower bound of the range
Quantity representing the upper bound of the range
0.1
Quantity Vector
Quantity Vector
QuantityType
Variable list of A
0.3.0
Defines an interface and partial implementation for types that represent a ratio between any two quantities
Defines an interface and partial implementation for types that represent a ratio between any two quantities
Quantity A
Quantity B
0.1
Root trait for representing Vectors
Root trait for representing Vectors
Type for the Vector's coordinate values
0.3.0
A marker trait identifying SI Base Units
A market trait identifying SI Units
Provides implicit conversions that allow BigDecimals to lead in * operations
Provides implicit conversions that allow BigDecimals to lead in * operations
BigDecimal(1.5) * Kilometers(10) should be(Kilometers(15))
Provides implicit conversions that allow Doubles to lead in * operations
Provides implicit conversions that allow Doubles to lead in * operations
1.5 * Kilometers(10) should be(Kilometers(15))
Provides implicit conversions that allow Longs to lead in * operations
Provides implicit conversions that allow Longs to lead in * operations
5 * Kilometers(10) should be(Kilometers(15))
A Unit of Measure that require a simple multiplier for converting to and from the underlying value's unit
A Unit of Measure is used to define the scale of a quantity measurement
A Unit of Measure is used to define the scale of a quantity measurement
Each Quantity Dimension must include at least one Unit of Measure, and one and only Primary. Other units of measure are defined with conversionFactors relative to the Primary.
The type of Quantity being measured
0.1
Singleton defining Metric System multipliers
Singleton defining Metric System multipliers
0.1
Factory singleton for squants.Dimensionless
Represents a unit of dozen (12)
Represents a unit of singles
Represents a unit of gross (144)
Singleton defining Metric System multipliers
Singleton defining Metric System multipliers
0.1
Represents a number of hundredths (0.01)
Represents a unit of scores (20)
0.1
0.1
Squants Market API
Squants Market API
Market Types are similar but not quite the same as other quantities in the library.
The primary type, squants.market.Money, is derived from Quantity, and its Units of Measure are Currencies. However, because the conversion multipliers between units can not be predefined, many of the behaviors have been overridden and augmented to realize correct behavior.
squants.market.Prices represent a Ratio between Money and some other Quantity. Prices can be created from ratios of Money and a Quantity
val money: Money = USD(10) val length: Length = Meters(1) val price: Price[Length] = money / length
Multiplying a Price * Quantity will yield Money amount that represents the cost of the quantity
val cost: Money = price * Meters(3.8)
and multiplying Price * Money will yield the corresponding Quantity amount
val budget: Money = USD(250) val quote: Length = price * budget
squants.market.CurrencyExchangeRates represent conversion rates between currencies. Use them to explicitly convert Money values in one currency to values in another.
squants.market.MoneyContext provide the implicit context necessary to perform cross-currency operations on Money values with conversions automatically applied.
Some binary math operations will work on Moneys of like Currency with no MoneyContext in scope. Attempts to perform these operations on Moneys of dissimilar currencies will throw an exception at runtime.
Other operations, including direct conversions to other currencies, require a MoneyContext and will not compile without it. However, there is no compile time check to determine if the correct exchange rates will be available at runtime. Operation requiring conversion without the required rates available will throw a NoSuchExchangeRateException at runtime.
The defaultMoneyContext uses the USD as the default and provides a list of ~20 common currencies, and NO exchange rates. If your application requires something different you should initialize your own implicit MoneyContext
0.1
0.1
0.1
0.1
0.1
0.1
0.1
0.1
Squants
The Scala API for Quantities, Units of Measure and Dimensional Analysis
Overview
Squants is a framework of data types and a domain specific language (DSL) for representing Quantities, their Units of Measure, and their Dimensional relationships. The API supports typesafe dimensional analysis, improved domain models and more. All types are immutable and thread-safe.
Typedefs and implicits for common usages
0.1
0.1