Packages

  • package root
    Definition Classes
    root
  • package squants

    The Scala API for Quantities, Units of Measure and Dimensional Analysis

    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

    Definition Classes
    root
    Version

    0.1

    Since

    0.1

  • package electro

    Definition Classes
    squants
    Since

    0.1

  • package energy

    Definition Classes
    squants
    Since

    0.1

  • package experimental
    Definition Classes
    squants
  • package information
    Definition Classes
    squants
  • package market

    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

    Definition Classes
    squants
    Since

    0.1

  • ARS
  • AUD
  • BRL
  • BTC
  • CAD
  • CHF
  • CLP
  • CNY
  • CZK
  • Currency
  • CurrencyExchangeRate
  • DKK
  • ETH
  • EUR
  • GBP
  • HKD
  • INR
  • JPY
  • KRW
  • LTC
  • MXN
  • MYR
  • Money
  • MoneyContext
  • MoneyConversions
  • NAD
  • NOK
  • NZD
  • NoSuchCurrencyException
  • NoSuchExchangeRateException
  • Price
  • RUB
  • SEK
  • USD
  • XAG
  • XAU
  • ZAR
  • package mass

    Definition Classes
    squants
    Since

    0.1

  • package motion

    Definition Classes
    squants
    Since

    0.1

  • package photo

    Definition Classes
    squants
    Since

    0.1

  • package radio

    Definition Classes
    squants
    Since

    0.1

  • package space

    Definition Classes
    squants
    Since

    0.1

  • package thermal

    Definition Classes
    squants
    Since

    0.1

  • package time

    Definition Classes
    squants
    Since

    0.1

p

squants

market

package market

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

Source
package.scala
Since

0.1

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. market
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. abstract class Currency extends UnitOfMeasure[Money]

    Represents a Currency, which is the Unit of Measure for Money

  2. case class CurrencyExchangeRate(base: Money, counter: Money) extends Ratio[Money, Money] with Product with Serializable

    Represent the rate of exchange between two currencies

    Represent the rate of exchange between two currencies

    base

    the base or "Fixed" currency (usually a value of 1 currency unit, but not required)

    counter

    the counter or "Variable" currency

    Since

    0.1

  3. final class Money extends Quantity[Money]

    Represents a quantity of Money.

    Represents a quantity of Money.

    Money is similar to other quantities in that it represents an amount of something - purchasing power - and it is measured in units - currencies.

    The main difference is that the conversion rate between currencies can not be certain at compile. (In fact it may not always be so easy to know them at runtime as well.)

    To address this diversion from the way most other quantities work, Money overrides several of the standard methods and operators to ensure one of two rules is followed:

    1) this and that are in the same currency, or 2) there is in an implicit MoneyContext in scope (which may or may not have the applicable exchange rate)

    Methods and operations applied to moneys of different currencies may throw a NoSuchExchangeRateException if the implicit MoneyContext does not contain the Rate(s) necessary to perform the conversion.

    The defaultMoneyContext includes USD as the default currency, a list of ~20 other currencies and NO exchange rates

    Since

    0.1

  4. case class MoneyContext(defaultCurrency: Currency, currencies: Set[Currency], rates: Seq[CurrencyExchangeRate], allowIndirectConversions: Boolean = true) extends Product with Serializable

    MoneyContext

    MoneyContext

    Provides a context for Money specific operations.

    When provided as an implicit parameter, the defaultCurrency will be used by the Money factory when no other currency is provided.

    Provides for cross-currency conversions.

    Will act as an implicit parameter to cross currency operations to allow for easy conversions

    defaultCurrency

    Currency used when none is supplied to the Money factory

    rates

    Collection of Exchange Rates used for currency conversions

    Since

    0.1

  5. case class NoSuchCurrencyException(code: String, fxContext: MoneyContext) extends Exception with Product with Serializable
  6. class NoSuchExchangeRateException extends Exception
  7. case class Price[A <: Quantity[A]](money: squants.Money, quantity: A) extends Ratio[squants.Money, A] with Serializable with Product

    Represents a price

    Represents a price

    A price is an squants.Ratio between a quantity of squants.market.Money and some other squants.Quantity

    A

    Quantity Type

    money

    Money

    quantity

    Quantity

    Since

    0.1

Value Members

  1. lazy val defaultCurrencySet: Set[Currency]
  2. lazy val defaultMoneyContext: MoneyContext
  3. object ARS extends Currency
  4. object AUD extends Currency
  5. object BRL extends Currency
  6. object BTC extends Currency
  7. object CAD extends Currency
  8. object CHF extends Currency
  9. object CLP extends Currency
  10. object CNY extends Currency
  11. object CZK extends Currency
  12. object Currency extends Serializable
  13. object DKK extends Currency
  14. object ETH extends Currency
  15. object EUR extends Currency
  16. object GBP extends Currency
  17. object HKD extends Currency
  18. object INR extends Currency
  19. object JPY extends Currency
  20. object KRW extends Currency
  21. object LTC extends Currency
  22. object MXN extends Currency
  23. object MYR extends Currency
  24. object Money extends Dimension[Money] with Serializable

    Factory singleton for Money

  25. object MoneyConversions

    Support for Money DSL

  26. object NAD extends Currency
  27. object NOK extends Currency
  28. object NZD extends Currency
  29. object RUB extends Currency
  30. object SEK extends Currency
  31. object USD extends Currency
  32. object XAG extends Currency
  33. object XAU extends Currency
  34. object ZAR extends Currency

Inherited from AnyRef

Inherited from Any

Ungrouped