Provides instances of Numeric[T]
for value classes.
I want to give meaningful types to values. I use value classes for this. Sometimes these are numeric, such as:
case class Quantity(value: Int) extends AnyVal
For numeric value classes it is sometimes convenient to be able to do:
Quantity(1) + Quantity(2)
This project enables basic numeric operations on numeric value classes.
Yeah, so I've not published this yet. If you want me to, raise an issue.
Otherwise, copy the source file (numeric.scala) and depend on shapeless (see project/Dependencies.scala).
Then:
Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.
scala> import io.underscore.numeric.Implicits._
import io.underscore.numeric.Implicits._
scala> import Numeric.Implicits._
import Numeric.Implicits._
scala> case class Count(value: Int) extends AnyVal
defined class Count
scala> Count(1) + Count(41)
res0: Count = Count(42)
See examples.scala for more usage.
Provide core numeric capabilities for value classes. This is not a units library and nor is it a maths library.