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

Add DefaultParser and DefaultParser0 typeclasses #577

Merged
merged 7 commits into from Apr 18, 2024

Conversation

morgen-peschke
Copy link
Contributor

These provide a way to bless canonical Parser/Parser0 instances and easily call them.

Implements #435

These provide a way to bless canonical `Parser`/`Parser0` instances and easily call them.
@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 94.68%. Comparing base (1e64b32) to head (e2d540e).

Files Patch % Lines
...c/main/scala/cats/parse/extra/DefaultParser0.scala 0.00% 4 Missing ⚠️
...rc/main/scala/cats/parse/extra/DefaultParser.scala 0.00% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@johnynek johnynek left a 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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@morgen-peschke
Copy link
Contributor Author

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?

I don't have any strong opinions about it being lawless.

I have the mild inclination that creating laws for DefaultParser0/DefaultParser0 would imply the existence of Coparser/Coparser0, but I have no idea if that's worth representing in the code as something other than A => String.

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
Copy link
Collaborator

@regadas regadas left a 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!

Copy link
Collaborator

@regadas regadas left a 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!

Copy link
Collaborator

@johnynek johnynek left a 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
Copy link
Collaborator

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.

Copy link
Contributor Author

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]
Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy enough 👍🏻

Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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 🙌

@johnynek johnynek merged commit be1d37a into typelevel:main Apr 18, 2024
13 checks passed
@morgen-peschke morgen-peschke deleted the add-DefaultParser-typeclass branch April 18, 2024 23:53
@morgen-peschke
Copy link
Contributor Author

Thanks for everyone's help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants