A Scala library for type-safe quantities, units of measure, and dimensional analysis.
Squants is a Scala library that provides a type-safe API for representing physical quantities, units of measure, and dimensional relationships. It solves the problem of runtime errors in dimensional analysis (e.g., accidentally adding kilowatts and kilowatt-hours) by enforcing correctness at compile time. The library includes a domain-specific language for expressive quantity manipulation and supports over 257 built-in units across 54 dimensions.
Scala developers working in scientific computing, engineering, finance, or any domain requiring rigorous unit handling and dimensional analysis. It is particularly useful for applications where unit conversions and type safety are critical to avoid errors.
Developers choose Squants because it eliminates entire classes of bugs through compile-time dimensional checking, offers a natural syntax for quantity expressions, and provides extensive built-in unit support. Its integration with Scala's type system and functional programming patterns makes it a robust alternative to using raw numeric types.
The Scala API for Quantities, Units of Measure and Dimensional Analysis
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Enforces that only quantities with the same dimensions can be compared or combined, preventing errors like adding power and energy, as shown in the README where such operations fail to compile.
Handles scale and type transformations seamlessly, allowing operations like adding kilowatts and megawatts without manual conversion, with methods like `in` and `to` for explicit control.
Provides an expressive syntax for quantity expressions, such as `100 kW` or `3.hours + 45.minutes`, making code more readable and intuitive, as demonstrated in the DSL section.
Includes over 257 units across 54 dimensions, covering scientific, engineering, and financial domains, reducing the need for custom implementations and manual conversions.
Requires familiarity with Scala's advanced type system, implicits, and functional patterns, which can be daunting for developers new to the library or less experienced with Scala.
Features like formatters, unit groups, and vector operations are marked as experimental or require verbose syntax (e.g., map methods for dimensional conversions), indicating potential instability or complexity.
Heavy reliance on implicits for the DSL and context handling (e.g., MoneyContext) can lead to cryptic compilation errors and requires careful scope management, increasing cognitive load.