Skip to content

Commit

Permalink
Logging-Refined integration #231
Browse files Browse the repository at this point in the history
  • Loading branch information
Ssstlis committed Apr 19, 2020
1 parent 3e1be4d commit 3523c0e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ lazy val loggingUtil = project
)
.dependsOn(loggingStr, concurrent)

lazy val loggingRefined = project
.in(file("logging/interop/refined"))
.settings(
defaultSettings,
publishName := "logging-refined",
libraryDependencies += refined
)
.dependsOn(loggingStr)

lazy val logging = project
.dependsOn(loggingStr, loggingDer, loggingLayout, loggingUtil)
.aggregate(loggingStr, loggingDer, loggingLayout, loggingUtil)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tofu.logging

import eu.timepit.refined.api.RefType
import eu.timepit.refined.api.RefType.ops.toRefTypeOps

package object refined {
implicit def deriveRefinedLoggable[T: Loggable, P, F[_, _]: RefType]: Loggable[F[T, P]] = {
Loggable[T].contramap(_.unwrap)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tofu.logging.refined

import eu.timepit.refined.types.numeric.{PosInt, PosLong}
import eu.timepit.refined.types.string.NonEmptyString
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers
import tofu.logging.Loggable._
import tofu.logging.Loggable

class TofuRefinedIntegrationSpec extends AnyFlatSpec with Matchers {
"derived loggable instances" should "be correct" in {
Loggable[PosInt].logShow(PosInt.unsafeFrom(1)) mustBe "1"
Loggable[PosLong].logShow(PosLong.unsafeFrom(1L)) mustBe "1"
Loggable[NonEmptyString].logShow(NonEmptyString.unsafeFrom("tofu")) mustBe "tofu"
}
}
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ object Dependencies {

val zioCats = "2.0.0.0-RC12"

val refined = "0.9.13"

// Compile time only
val macroParadise = "2.1.1"

Expand Down Expand Up @@ -74,6 +76,7 @@ object Dependencies {
val zio = "dev.zio" %% "zio" % Version.zio
val zioCats = "dev.zio" %% "zio-interop-cats" % Version.zioCats
val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest % Test
val refined = "eu.timepit" %% "refined" % Version.refined

// Compile-time only
val macroParadise = "org.scalamacros" % "paradise" % Version.macroParadise cross CrossVersion.patch
Expand Down

0 comments on commit 3523c0e

Please sign in to comment.