-
-
Notifications
You must be signed in to change notification settings - Fork 111
Open
Labels
Description
What do you think about baking such an extension into jsoniter? Being able to map over codecs is quite helpful.
extension [A](underlying: JsonValueCodec[A]) {
def imap[B](f: A => B)(g: B => A): JsonValueCodec[B] = new JsonValueCodec[B] {
def decodeValue(in: JsonReader, default: B): B = {
f(underlying.decodeValue(in, underlying.nullValue))
}
def encodeValue(x: B, out: JsonWriter): Unit = {
underlying.encodeValue(g(x), out)
}
def nullValue: B = f(underlying.nullValue)
}
}