Created
April 30, 2016 10:06
-
-
Save AntonFagerberg/5ce9ab0a1383d9da0cd5f2eca91b2208 to your computer and use it in GitHub Desktop.
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
object Example extends App { | |
def DynamicOption(value: DynamicType) = Option(value) | |
val a = DynamicOption(1) | |
val b = DynamicOption("hello") | |
val result: Option[DynamicType] = | |
for { | |
aa <- a | |
bb <- b | |
} yield { | |
aa + bb | |
} | |
// Mock dynamic type system | |
implicit def intToDynamic(i: Int): DynamicType = DynamicType(i) | |
implicit def stringToDynamic(s: String): DynamicType = DynamicType(s) | |
case class DynamicType(value: Any) { | |
implicit def anyToString(a: Any): String = a.asInstanceOf[String] | |
implicit def anyToInt(a: Any): Int = a.asInstanceOf[Int] | |
def +(other: DynamicType): DynamicType = { | |
DynamicType(value + other) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment