Skip to content

Instantly share code, notes, and snippets.

@japgolly
Last active August 29, 2015 14:02
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 japgolly/816902779c457f25c87f to your computer and use it in GitHub Desktop.
Save japgolly/816902779c457f25c87f to your computer and use it in GitHub Desktop.
CodecJson.xmap
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