underscoreio/numeric-vc

Name: numeric-vc

Owner: Underscore

Description: Derives instances of Numeric for value classes

Created: 2016-12-10 22:56:01.0

Updated: 2017-02-27 22:47:10.0

Pushed: 2016-12-11 14:06:04.0

Homepage: null

Size: 14

Language: Scala

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Numeric Value Classes

CircleCI Join the chat at https://gitter.im/underscoreio/scala

Summary

Provides instances of Numeric[T] for value classes.

What?

I want to give meaningful types to values. I use value classes for this. Sometimes these are numeric, such as:

 class Quantity(value: Int) extends AnyVal

For numeric value classes it is sometimes convenient to be able to do:

tity(1) + Quantity(2)

This project enables basic numeric operations on numeric value classes.

Usage

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:

ome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
 in expressions for evaluation. Or try :help.

a> import io.underscore.numeric.Implicits._
rt io.underscore.numeric.Implicits._

a> import Numeric.Implicits._
rt Numeric.Implicits._

a> case class Count(value: Int) extends AnyVal
ned class Count

a> Count(1) + Count(41)
: Count = Count(42)

See examples.scala for more usage.

Mission Statement

Provide core numeric capabilities for value classes. This is not a units library and nor is it a maths library.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.