-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #103 - [refined4s-circe] Add Encoder and Decoders for Newtype, …
…Refined and InlinedRefined with Coercible and RefinedCtor
- Loading branch information
Showing
3 changed files
with
1,432 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
.../refined4s-circe/shared/src/main/scala/refined4s/modules/circe/derivation/instances.scala
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
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 |
Oops, something went wrong.