Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Show type class #412

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

WIP: Show type class #412

wants to merge 4 commits into from

Conversation

fthomas
Copy link
Owner

@fthomas fthomas commented Jan 15, 2018

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
Copy link
Owner Author

fthomas commented Jan 15, 2018

This could be also an opportunity to address #104.

@codecov
Copy link

codecov bot commented Jan 15, 2018

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%) ⬇️
...epit/refined/internal/RefinePartiallyApplied.scala 57.14% <0%> (-42.86%) ⬇️
...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%) ⬇️

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.

@kusamakura
Copy link
Contributor

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.

@fthomas
Copy link
Owner Author

fthomas commented Apr 6, 2018

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

@satorg
Copy link

satorg commented Sep 24, 2021

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

@mergify mergify bot added the core label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants