Does Scala have modulo in the standard library?

scala

Solution

`%` is modulo. Scala does not have the zero-or-positive version that you wrote above.

You could write the code generically using `scala.math.Integral`, but it would be so slow that you wouldn't want to use it.

Just write it all out. It should take you only slightly longer than it did to ask this question.

Problem

I'm assuming the answer is no because I can't find it, but it wouldn't be the first time I'd be wrong about that. Meanwhile I usually define it like this: ``` implicit class IntWithMod(x: Int) { def mod(y: Int) = x%y+(if (x < 0) y else 0) } ``` Is there a scala library (ideally the standard library, external works too though if it's not huge) that defines this? If not, is there some easy way to add this to all integral types (doing this manually for each one is kinda tedious).

Original source