refined icon indicating copy to clipboard operation
refined copied to clipboard

WIP: Show type class

Open fthomas opened this issue 7 years ago • 5 comments

This is an attempt to allow for custom error messages (#161) and to improve string representations of compound predicates like type LessEqual[N] = Not[Greater[N]] (#49) using a dedicated Show type class.

First results look promising:

// using showExpr and showResult from Show

scala> refineV[LessEqual[_5]].apply2(10)
res1: Either[String,api.Refined[Int,numeric.LessEqual[shapeless.nat._5]]] =
  Left(Predicate failed: (10 <= 5).)

scala> refineV[NonEmpty].apply2("")
res2: Either[String,api.Refined[String,collection.NonEmpty]] =
  Left(Cannot create a NonEmptyString with the empty string)

// using showExpr and showResult from Validate

scala> refineV[LessEqual[_5]].apply(10)
res3: Either[String,api.Refined[Int,numeric.LessEqual[shapeless.nat._5]]] =
  Left(Predicate (10 > 5) did not fail.)

scala> refineV[NonEmpty].apply("")
res4: Either[String,api.Refined[String,collection.NonEmpty]] =
  Left(Predicate isEmpty() did not fail.)

fthomas avatar Jan 15 '18 20:01 fthomas

This could be also an opportunity to address #104.

fthomas avatar Jan 15 '18 20:01 fthomas

Codecov Report

Merging #412 into master will decrease coverage by 2.34%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #412      +/-   ##
==========================================
- Coverage   95.51%   93.16%   -2.35%     
==========================================
  Files          46       47       +1     
  Lines         557      571      +14     
  Branches       12       10       -2     
==========================================
  Hits          532      532              
- Misses         25       39      +14
Impacted Files Coverage Δ
...ed/src/main/scala/eu/timepit/refined/numeric.scala 64.28% <0%> (-4.95%) :arrow_down:
...epit/refined/internal/RefinePartiallyApplied.scala 57.14% <0%> (-42.86%) :arrow_down:
...d/src/main/scala/eu/timepit/refined/api/Show.scala 0% <0%> (ø)
...red/src/main/scala/eu/timepit/refined/string.scala 91.89% <0%> (-8.11%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c223dab...a6a173b. Read the comment docs.

codecov[bot] avatar Jan 15 '18 20:01 codecov[bot]

If we can separate out the result display part of Validate into this Show typeclass, I think the concern you raised in #397 can also be addressed cleanly.

kusamakura avatar Apr 06 '18 10:04 kusamakura

You're right @kusamakura. This is painful lesson in keeping type classes focused on one concern.

fthomas avatar Apr 06 '18 19:04 fthomas

Hi guys. Just wondering – any activity on this PR? Seems this functionality is a really nice-to-have one.

satorg avatar Sep 24 '21 19:09 satorg