Created
January 4, 2011 11:20
-
-
Save kmizu/764667 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
trait Or[+A, +B] | |
case class LOr[+A, +B](a: A) extends Or[A, B] | |
case class ROr[+A, +B](b: B) extends Or[A, B] | |
implicit def lOr[A, B](implicit a: A): Or[A, B] = LOr[A, B](a) | |
implicit def rOr[A, B](implicit b: B): Or[A, B] = ROr[A, B](b) | |
def valueIsIntOrString[T](value: T)(implicit param: Or[T => String, T => Int]) = param match { | |
case LOr(t2String) => | |
println("value is String") | |
println(t2String(value)) | |
case ROr(t2Int) => | |
println("value is Int") | |
println(t2Int(value)) | |
} | |
valueIsIntOrString(100) | |
valueIsIntOrString("Foo") | |
// valueIsIntOrString(1.0) // Compilation Error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment