Skip to content

Commit

Permalink
use TraceableValue.stringToTraceValue instead of TraceableValue[Strin…
Browse files Browse the repository at this point in the history
…g] to avoid infinite recursion
  • Loading branch information
bpholt committed Jan 22, 2023
1 parent 83dcc18 commit 5f761f8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/src/main/scala/com/dwolla/tracing/ToTraceValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import natchez.{TraceValue, TraceableValue}
object LowPriorityTraceableValueInstances extends LowPriorityTraceableValueInstances

trait LowPriorityTraceableValueInstances extends LowestPriorityTraceableValueInstances {
implicit val unitTraceableValue: TraceableValue[Unit] = TraceableValue[String].contramap(_ => "()")
implicit val unitTraceableValue: TraceableValue[Unit] =
TraceableValue.stringToTraceValue.contramap(_ => "()")

implicit def optionalTraceValue[A: TraceableValue]: TraceableValue[Option[A]] = new TraceableValue[Option[A]] {
override def toTraceValue(a: Option[A]): TraceValue = a match {
case Some(a) => TraceableValue[A].toTraceValue(a)
case None => TraceValue.StringValue("None")
}
implicit def optionalTraceValue[A: TraceableValue]: TraceableValue[Option[A]] = {
case Some(a) => TraceableValue[A].toTraceValue(a)
case None => TraceValue.StringValue("None")
}

implicit def traceValueViaJson[A: Encoder]: TraceableValue[A] = _.asJson.noSpaces
implicit def traceValueViaJson[A: Encoder]: TraceableValue[A] =
TraceableValue.stringToTraceValue.contramap(_.asJson.noSpaces)
}

trait LowestPriorityTraceableValueInstances {
implicit def traceValueViaShow[A: Show]: TraceableValue[A] = _.show
implicit def traceValueViaShow[A: Show]: TraceableValue[A] =
TraceableValue.stringToTraceValue.contramap(_.show)
}

0 comments on commit 5f761f8

Please sign in to comment.