Last active
August 29, 2015 14:02
-
-
Save japgolly/816902779c457f25c87f to your computer and use it in GitHub Desktop.
CodecJson.xmap
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
case class Username(value: String) | |
implicit val usernameCodec = implicitly[CodecJson[String]].xmap(Username.apply)(_.value) | |
// ------------------------------------------------------------------------------------------------ | |
// Would like to eventually like to do something like this: | |
// (Basically a replacement the {@@, T with U} hack which has caused me too many problems) | |
trait TaggedType { type U; def value: U } | |
trait TaggedTypeCtor[T <: TaggedType] { def apply(u: T#U): T } | |
implicit def codecTagged[T <: TaggedType](implicit TC: TaggedTypeCtor[T], c: CodecJson[T#U]): CodecJson[T] = | |
c.xmap(TC.apply)(_.value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment