typelevel / algebra
1
package algebra
2
package instances
3

4
import algebra.lattice._
5
import algebra.ring._
6

7
package object int extends IntInstances
8

9
trait IntInstances extends cats.kernel.instances.IntInstances {
10
  implicit val intAlgebra: IntAlgebra =
11 2
    new IntAlgebra
12

13
  val IntMinMaxLattice: BoundedDistributiveLattice[Int] =
14 2
    BoundedDistributiveLattice.minMax[Int](Int.MinValue, Int.MaxValue)
15
}
16

17
class IntAlgebra extends CommutativeRing[Int] with Serializable {
18

19 2
  def zero: Int = 0
20 2
  def one: Int = 1
21

22 2
  def plus(x: Int, y: Int): Int = x + y
23 2
  def negate(x: Int): Int = -x
24 2
  override def minus(x: Int, y: Int): Int = x - y
25

26 2
  def times(x: Int, y: Int): Int = x * y
27

28
  override def pow(x: Int, y: Int): Int =
29 2
    StaticMethods.pow(x.toLong, y.toLong).toInt
30

31
  override def fromInt(n: Int): Int = n
32 2
  override def fromBigInt(n: BigInt): Int = n.toInt
33
}

Read our documentation on viewing source code .

Loading