Skip to content

Instantly share code, notes, and snippets.

@AntonFagerberg
Created April 30, 2016 10:06
Show Gist options
  • Save AntonFagerberg/5ce9ab0a1383d9da0cd5f2eca91b2208 to your computer and use it in GitHub Desktop.
Save AntonFagerberg/5ce9ab0a1383d9da0cd5f2eca91b2208 to your computer and use it in GitHub Desktop.
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