argonaut icon indicating copy to clipboard operation
argonaut copied to clipboard

Override mapJson in CodecJson

Open enzief opened this issue 6 years ago • 2 comments

Does it make sense to

sealed abstract class CodecJson[A] ... {
  override def mapJson(f: Json => Json): CodecJson[A] =
    CodecJson.derived(
      Encoder.mapJson(f),
      Decoder
    )
}

?

enzief avatar Feb 19 '19 22:02 enzief

Surely it would need an inverse for the decoder?

seanparsons avatar Feb 19 '19 23:02 seanparsons

Right. As there's no contramapJson for Decoder would it be correct to add

trait Decoder[A] {
  def contramapJson(f: Json => Json): Decoder[A] // not sure about this signature
}

abstract class CodecJson[A] {
  def xmapJson(f: Json => Json): CodecJson[A]
}

enzief avatar Feb 20 '19 10:02 enzief