Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
Created December 29, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakatsuka/e3e218e62ee9d3d2c44e5a8e7c9aff6e to your computer and use it in GitHub Desktop.
Save dakatsuka/e3e218e62ee9d3d2c44e5a8e7c9aff6e to your computer and use it in GitHub Desktop.
trait WrappedNumericLike[A] {
def value: A
}
abstract class WrappedNumeric[A, N <: WrappedNumericLike[A]](value: A)(implicit num: Integral[A])
extends WrappedNumericLike[A] {
val companion: A => N
def +(x: N): N = companion(num.plus(value, x.value))
def -(x: N): N = companion(num.minus(value, x.value))
def /(x: N): N = companion(num.quot(value, x.value))
def /(x: A): N = companion(num.quot(value, x))
def %(x: N): N = companion(num.rem(value, x.value))
def %(x: A): N = companion(num.rem(value, x))
def <=(x: N): Boolean = num.lteq(value, x.value)
def >=(x: N): Boolean = num.gteq(value, x.value)
def <(x: N): Boolean = num.lt(value, x.value)
def >(x: N): Boolean = num.gt(value, x.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment