Created
December 29, 2017 07:00
-
-
Save dakatsuka/e3e218e62ee9d3d2c44e5a8e7c9aff6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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