Created
November 26, 2016 10:30
-
-
Save taig/03386fa584bd48f392f9d812b1c86072 to your computer and use it in GitHub Desktop.
Circe Value Class codecs
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
implicit def decoderValueClass[T <: AnyVal, V]( | |
implicit | |
g: Lazy[Generic.Aux[T, V :: HNil]], | |
d: Decoder[V] | |
): Decoder[T] = Decoder.instance { cursor ⇒ | |
d( cursor ).map { value ⇒ | |
g.value.from( value :: HNil ) | |
} | |
} | |
implicit def encoderValueClass[T <: AnyVal, V]( | |
implicit | |
g: Lazy[Generic.Aux[T, V :: HNil]], | |
e: Encoder[V] | |
): Encoder[T] = Encoder.instance { value ⇒ | |
e( g.value.to( value ).head ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment