We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invariant[Numeric]
Here's a ready instance one can use:
implicit val invariantNumeric: Invariant[Numeric] = new Invariant[Numeric] { def imap[A, B](fa: Numeric[A])(f: A => B)(g: B => A): Numeric[B] = new Numeric[B] { def compare(x: B, y: B): Int = fa.compare(g(x), g(y)) def plus(x: B, y: B): B = f(fa.plus(g(x), g(y))) def minus(x: B, y: B): B = f(fa.minus(g(x), g(y))) def times(x: B, y: B): B = f(fa.times(g(x), g(y))) def negate(x: B): B = f(fa.negate(g(x))) def fromInt(x: Int): B = f(fa.fromInt(x)) def toInt(x: B): Int = fa.toInt(g(x)) def toLong(x: B): Long = fa.toLong(g(x)) def toFloat(x: B): Float = fa.toFloat(g(x)) def toDouble(x: B): Double = fa.toDouble(g(x)) } }
Feel free to grab it if you have time before I do.
The text was updated successfully, but these errors were encountered:
I'll do it now!
Sorry, something went wrong.
Would there be any issues doing this for scala.math.Integral and scala.math.Fractional as well? These inherit from Numeric.
scala.math.Integral
scala.math.Fractional
Numeric
Successfully merging a pull request may close this issue.
Here's a ready instance one can use:
Feel free to grab it if you have time before I do.
The text was updated successfully, but these errors were encountered: