-
Notifications
You must be signed in to change notification settings - Fork 53
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 DefaultParser and DefaultParser0 typeclasses #577
Add DefaultParser and DefaultParser0 typeclasses #577
Conversation
These provide a way to bless canonical `Parser`/`Parser0` instances and easily call them.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #577 +/- ##
==========================================
- Coverage 95.13% 94.68% -0.45%
==========================================
Files 10 12 +2
Lines 1480 1487 +7
Branches 330 332 +2
==========================================
Hits 1408 1408
- Misses 72 79 +7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty good to me. We need to fix the header check (which I find a bit annoying but sbt-typelevel sets it up).
I also wonder a bit about this typeclass being lawless.
It could be a lawful typeclass if paired with a function that converts A to String and the law is that we can always parse and get back the original.
What do you think about the lawlessness?
} | ||
|
||
implicit def defaultParserIsDefaultParser0[A: DefaultParser]: DefaultParser0[A] = | ||
DefaultParser0.instance(DefaultParser[A].parser) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need DefaultParser0 here do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not particularly, I'll occasionally include the object for methods that are kind of generic.
I don't have strong feelings about it, and am happy to remove it if you prefer
I don't have any strong opinions about it being lawless. I have the mild inclination that creating laws for It'd probably make testing parsers over the set of valid inputs easier, so it might be worth doing for that reason alone. |
Actually used `sbt headerCreateAll` this time, like I should have the first time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! 👍 but I'll let @johnynek do the follow up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! 👍 but I'll let @johnynek do the follow up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the latency on my part.
Two minor requests then I'll merge.
Thanks for sending this PR.
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package cats.parse.extra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should put this in the main package. There are very few names in cats.parse already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do 👍🏻
* @tparam A | ||
*/ | ||
trait DefaultParser0[+A] { | ||
def parser0: Parser0[A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add plumbing through parse and parseAll here so you can do: DefaultParser[Foo].parseAll(s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy enough 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this change yet. Did you reconsider this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's up, my guess is it took a couple minutes to propagate to the UI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a good idea 🙌
Thanks for everyone's help :) |
These provide a way to bless canonical
Parser
/Parser0
instances and easily call them.Implements #435