Skip to content

Instantly share code, notes, and snippets.

@evantill
Last active December 17, 2015 01:59
Show Gist options
  • Save evantill/5532308 to your computer and use it in GitHub Desktop.
Save evantill/5532308 to your computer and use it in GitHub Desktop.
replacing all occurences of Order by Enum failed
import scalaz.Order
import scalaz.syntax.order._
case class MyRange[A: Order](l: A, h: A){
def myMethod(b: MyRange[A]): MyRange[A] = {
MyRange[A](l min b.l, h max b.h)
}
}
object MyRange {
def myMethod[A: Order](a: MyRange[A], b: MyRange[A]): MyRange[A] = {
MyRange[A](a.l min b.l, a.h max b.h)
}
}
//test
import org.scalatest.FunSuite
class MyRangeSpecs extends FunSuite {
test("test implicit in companion object") {
val v1 = MyRange(1, 2)
val v2 = MyRange(3, 4)
val v3 = MyRange.myMethod(v1, v2)
assert(v3 === MyRange(1, 4))
}
test("test implicit with case class method in companion object") {
val v1 = MyRange(1, 2)
val v2 = MyRange(3, 4)
val v3 = v1 myMethod v2
assert(v3 === MyRange(1, 4))
}
test("test BigInt range ") {
val v1 = MyRange(BigInt(1), BigInt(2))
val v2 = MyRange(BigInt(3), BigInt(4))
val v3 = v1 myMethod v2
assert(v3 === MyRange(BigInt(1), BigInt(4)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment