Created
January 11, 2011 22:52
-
-
Save lopex/775330 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 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