Last active
August 29, 2015 14:10
-
-
Save rodrigopr/b61bb1f99edc87f334c1 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
trait Facade[A] { | |
def decode(json: String): A | |
} | |
trait DecodeJson[A] { | |
def apply(json: String): A | |
} | |
implicit def toDecode[A](implicit facade: Facade[A]): DecodeJson[A] = { | |
new DecodeJson[A] { | |
def apply(json: String): A = facade.decode(json) | |
} | |
} | |
def parse[A](json: String)(implicit decode: DecodeJson[A]): A = decode(json) | |
implicit object LongDecoder extends Facade[Long] { | |
def decode(json: String): Long = json.toLong | |
} | |
val x = parse[Long]("123") | |
//x: Long = 123 | |
val x: Long = parse("123") | |
//x: Long = 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment