Last active
December 17, 2015 01:59
-
-
Save evantill/5532308 to your computer and use it in GitHub Desktop.
replacing all occurences of Order by Enum failed
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
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