refined
refined copied to clipboard
WIP: Show type class
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.)
This could be also an opportunity to address #104.
Codecov Report
Merging #412 into master will decrease coverage by
2.34%
. The diff coverage is0%
.
@@ 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.
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.
You're right @kusamakura. This is painful lesson in keeping type classes focused on one concern.
Hi guys. Just wondering – any activity on this PR? Seems this functionality is a really nice-to-have one.