Skip to content

Commit

Permalink
Close #103 - [refined4s-circe] Add Encoder and Decoders for Newtype, …
Browse files Browse the repository at this point in the history
…Refined and InlinedRefined with Coercible and RefinedCtor
  • Loading branch information
kevin-lee committed Dec 11, 2023
1 parent 5a3e03d commit be27544
Show file tree
Hide file tree
Showing 3 changed files with 1,432 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package refined4s.modules.circe.derivation

import io.circe.{Decoder, Encoder}
import refined4s.{Coercible, RefinedCtor}
import refined4s.syntax.*

/** @author Kevin Lee
* @since 2023-12-11
*/
trait instances {

given derivedEncoder[A, B](using coercible: Coercible[A, B], encoder: Encoder[B]): Encoder[A] =
a => encoder(coercible(a))

given derivedNewtypeDecoder[A, B](using coercible: Coercible[A, B], decoder: Decoder[A]): Decoder[B] =
Coercible.unsafeWrapM(decoder)

given derivedRefinedDecoder[A, B](using refinedCtor: RefinedCtor[B, A], decoder: Decoder[A]): Decoder[B] =
decoder.emap(refinedCtor.create)
}
object instances extends instances
Loading

0 comments on commit be27544

Please sign in to comment.