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

Extend from Parser #284

Merged
merged 1 commit into from
Nov 4, 2022
Merged

Extend from Parser #284

merged 1 commit into from
Nov 4, 2022

Conversation

TimoMeijer
Copy link
Contributor

@TimoMeijer TimoMeijer commented Feb 28, 2022

Extending from Parser adds some convenience methods to the Parser out of the box, such as decodeAccumulating.
The parser package object already matches the Parser interface.

Relates to #199

Extending from Parser adds some convenience methods to the Parser out of the box, such as `decodeAccumulating`.
The parser package object already matches the Parser interface.
@TimoMeijer
Copy link
Contributor Author

@zmccoy @jeffmay Would you have time to take a look? Thanks!

@SethTisue
Copy link

(As an aside, I see that readme in this repo still names Travis as a maintainer.)

Copy link
Member

@zmccoy zmccoy left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

@zmccoy
Copy link
Member

zmccoy commented Mar 15, 2022

@TimoMeijer A preemptive approval when I thought I saw it green on my part. So it looks like things run fine on 2.11, and 2.12. On 2.13 however, when extending Parser on the package object it compiles, but ends up acting as if the def parse(yaml: Reader): Either[ParsingFailure, Json] definition doesn't exist and that the method that takes a string is the only one. Changing names would break bincompat, and I'm honestly not sure if this is a bug in the 2.13 compiler or an expected change yet.

@zmccoy zmccoy self-requested a review March 15, 2022 17:54
@TimoMeijer
Copy link
Contributor Author

I can see if I can reproduce this locally tomorrow, and if so, investigate further

@TimoMeijer
Copy link
Contributor Author

The compile error actually occurs in both 2,12 and 2.13, but not in 3.
If I change the package object into a regular object, the error disappears.
I have not yet figured out why this is the case, but I'll do some more research.

@TimoMeijer
Copy link
Contributor Author

Minimal example of the behavior: https://gist.github.com/TimoMeijer/bef21c11cb13fa283205de1dd32347d2

@zmccoy
Copy link
Member

zmccoy commented Mar 16, 2022

That looks to track with what we found when we were looking at things, I missed the 2.12 failure though but that makes sense.

@TimoMeijer
Copy link
Contributor Author

TimoMeijer commented Mar 16, 2022

@zmccoy Would it make sense to split the implementation of parser between 2.x and 3.x, as we can support this behavior on 3.x already? Or would we not want to implement this, and have the inconsistency between circe and circe-yaml until 2.x support is dropped? Or check if there might be any workarounds?

@jeremyrsmith
Copy link
Collaborator

Sorry, I know I don't maintain this anymore. But I want to ask:

Do you want to extends Parser so that this package can be substituted for a Parser? Or is it just to inherit the < 20 lines of code that Parser gives you?

I'd hope it's not the former, because you can't substitute a JSON parser for a YAML parser (nor vice versa, necessarily).

I'd hope it's not the latter, because those methods aren't special enough to couple these.

Just my opinion as an ex-maintainer.

@TimoMeijer
Copy link
Contributor Author

TimoMeijer commented Mar 16, 2022

Thanks for your thoughts @jeremyrsmith!

My original case was that I wanted to use decodeAccumulating with yaml files. On looking into it further, I noticed it was implemented on the Parser trait in circe core, which the circe builtin jawn parser module implements. It seemed logical that the yaml parser should be implemented similarly, and inherit the same functionality and convenience methods.

You're of course completely right that simply copying over decode and decodeAccumulating would add the same
convenience methods. Personally, I would argue that extending Parser would be a more future-proof implementation, over duplicating the convenience methods, as it would ensure circe parser and circe-yaml parser methods stay inline. Although this compiler bug makes that choice less straightforward.

@jeremyrsmith, is your point that we should add these convenience methods, but not through extending from Parser, or that we shouldn't add these conveniences at all?

@jeremyrsmith
Copy link
Collaborator

@TimoMeijer I guess my point is that, in Parser, the desired method decodeAccumulating is just composing parse and then the decoder's decode. The details of composing an Either[E, T] with a T => ValidatedNel[E, T] are not likely to change, so extending an interface just to inherit that well-defined method might not be worth the trouble it's causing.

Another solution would be to pull out the implementation in question to a function. Would that seem silly for the method in question?

Again, sorry to butt in here. Not trying to imply I have answers.

But extending Parser might be an XY problem @zmccoy 😉

@zarthross zarthross merged commit 390ad38 into circe:master Nov 4, 2022
@zarthross
Copy link
Member

Whops, sorry, was working on an alternative and accidentally pushed into master... I've fixed that, this isn't really merged in.. 😞

@zarthross
Copy link
Member

@TimoMeijer Thoughts on #338?

@TimoMeijer
Copy link
Contributor Author

TimoMeijer commented Nov 4, 2022 via email

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.

5 participants