Skip to content

Commit

Permalink
Add ciris module
Browse files Browse the repository at this point in the history
  • Loading branch information
taig committed Mar 14, 2024
1 parent 989b316 commit 6527ec4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
17 changes: 15 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
val Version = new {
val Cats = "2.10.0"
val Circe = "0.14.6"
val Ciris = "3.5.0"
val Munit = "0.7.29"
val Scala = "3.3.3"
}
Expand All @@ -18,7 +19,7 @@ inThisBuild(
)
)

lazy val root = project
lazy val root = crossProject(JVMPlatform)
.in(file("."))
.enablePlugins(BlowoutYamlPlugin)
.settings(noPublishSettings)
Expand All @@ -31,7 +32,7 @@ lazy val root = project
},
name := "enumeration-ext"
)
.aggregate(core.jvm, core.js, circe.jvm, circe.js)
.aggregate(core, circe, ciris)

lazy val core = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
Expand Down Expand Up @@ -62,3 +63,15 @@ lazy val circe = crossProject(JVMPlatform, JSPlatform)
name := "enumeration-ext-circe"
)
.dependsOn(core % "compile->compile;test->test")

lazy val ciris = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.withoutSuffixFor(JVMPlatform)
.in(file("modules/ciris"))
.settings(
libraryDependencies ++=
"is.cir" %% "ciris" % Version.Ciris ::
Nil,
name := "enumeration-ext-ciris"
)
.dependsOn(core % "compile->compile;test->test")
16 changes: 16 additions & 0 deletions modules/ciris/src/main/scala/io/taig/enumeration/ext/ciris.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.taig.enumeration.ext

import cats.syntax.all.*
import cats.{Hash, Show}
import _root_.ciris.ConfigDecoder

trait ciris:
given conficDecoder[A, B, C: Show](using mapping: Mapping[B, C], decoder: ConfigDecoder[A, C]): ConfigDecoder[A, B] =
ConfigDecoder[A, C].mapOption(typeName = mapping.values.map(mapping.inj).map(_.show).mkString("|"))(mapping.prj)

def decoderEnumeration[A, B, C: Show: Hash](
f: B => C
)(using EnumerationValues.Aux[B, B])(using decoder: ConfigDecoder[A, C]): ConfigDecoder[A, B] =
conficDecoder(using Show[C], Mapping.enumeration(f), decoder)

object ciris extends ciris

0 comments on commit 6527ec4

Please sign in to comment.