Skip to content

Instantly share code, notes, and snippets.

@rodrigopr
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigopr/b61bb1f99edc87f334c1 to your computer and use it in GitHub Desktop.
Save rodrigopr/b61bb1f99edc87f334c1 to your computer and use it in GitHub Desktop.
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