-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add RefinedTypeOps for companion objects of refined types #369
Conversation
Codecov Report
@@ Coverage Diff @@
## master #369 +/- ##
==========================================
- Coverage 98.94% 96.57% -2.38%
==========================================
Files 39 41 +2
Lines 476 497 +21
Branches 8 10 +2
==========================================
+ Hits 471 480 +9
- Misses 5 17 +12
Continue to review full report at Codecov.
|
Another advantage of this approach over a macro that just adds some functions to an object is that we can easily add extension methods to any refined type companion. See #382 for details. |
This is a solution for #342 but unlike #346 it does not add a new macro. Compared to a macro solution, companion objects need be written manually and require a little bit boilerplate. E.g. for a refined type
type PosInt = Int Refined Positive
one would need to write a companion that extends fromRefinedTypeOps
like this:Usage then looks like:
So this PR adds the
RefinedTypeOps
class to simplify the definition of companion objects of refined types, theRefinedType
type class that combinesRefType
andValidate
instances of a refined type (thus making #193 obsolete), and companion objects for refined types in theeu.timepit.refined.types
package.