Skip to content

Commit

Permalink
Implicitly use Show[Expectation] (#624)
Browse files Browse the repository at this point in the history
* Implicitly use Show[Expectation]

* format
  • Loading branch information
johnynek authored Nov 17, 2024
1 parent 7ce8470 commit 6a8e798
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/shared/src/main/scala/cats/parse/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -974,13 +974,14 @@ object Parser {
def unapply(error: Error): Option[(Int, NonEmptyList[Expectation])] =
Some((error.failedAtOffset, error.expected))

implicit val catsShowError: Show[Error] =
implicit def catsShowErrorGivenExpectation(implicit showExp: Show[Expectation]): Show[Error] =
new Show[Error] {
def show(error: Error): String = {
val nl = "\n"

def errorMsg = {
val expectations = error.expected.toList.iterator.map(e => s"* ${e.show}").mkString(nl)
val expectations =
error.expected.toList.iterator.map(e => s"* ${showExp.show(e)}").mkString(nl)

s"""|expectation${if (error.expected.tail.nonEmpty) "s" else ""}:
|$expectations""".stripMargin
Expand Down Expand Up @@ -1037,6 +1038,9 @@ object Parser {
}
}
}

// This is here for binary compatibility, but no longer implicit
val catsShowError: Show[Error] = catsShowErrorGivenExpectation(Expectation.catsShowExpectation)
}

/** Enables syntax to access product01, product and flatMap01 This helps us build Parser instances
Expand Down

0 comments on commit 6a8e798

Please sign in to comment.