Skip to content

Instantly share code, notes, and snippets.

@lopex
Created January 11, 2011 22:52
Show Gist options
  • Save lopex/775330 to your computer and use it in GitHub Desktop.
Save lopex/775330 to your computer and use it in GitHub Desktop.
object ord {
abstract trait Converter[Dupa, T] {
def apply(a: String): T
}
class Dupa(s: String) {
def or[T](a: T)(implicit conv: Converter[Dupa, T]): T = conv(s)
}
object Dupa {
implicit object IntConv extends Converter[Dupa, Int] {
def apply(a: String) = a.toInt
}
implicit object DoubleConv extends Converter[Dupa, Double] {
def apply(a: String) = a.toDouble
}
}
def main(a: Array[String]) {
val dupa = new Dupa("4")
val a: Int = dupa or 1
println(a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment