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 JsonDecoder Algebra #2907

Merged
merged 3 commits into from Nov 26, 2019

Conversation

ChristopherDavenport
Copy link
Member

Single Type Abstraction for separation of Sync and the locations using the Json, which is primarily businesss logic where we'd prefer to remove effects.

@@ -115,6 +115,12 @@ trait CirceInstances extends JawnInstances {
Uri.fromString(str).leftMap(_ => "Uri")
}

implicit class JsonDecoderSyntax[F[_]: JsonDecoder](private val req: Message[F])(
implicit F: JsonDecoder[F]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it already specified as F context bound?
(also - don't you want to move this constraint to methods to avoid JsonDecoderSyntax allocation with extends AnyVal trick?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops. Yes. I switched how I was invoking it and left the old one. will fix these two.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't extend AnyVal because of our position -

value class may not be a member of another class - We could move these syntax's out but it would be a lot more involved move that I think I would rather do separately from this concept.

@@ -115,6 +115,11 @@ trait CirceInstances extends JawnInstances {
Uri.fromString(str).leftMap(_ => "Uri")
}

implicit class JsonDecoderSyntax[F[_]](private val req: Message[F])(implicit F: JsonDecoder[F]) {

This comment was marked as resolved.

This comment was marked as resolved.

@@ -115,6 +115,11 @@ trait CirceInstances extends JawnInstances {
Uri.fromString(str).leftMap(_ => "Uri")
}

implicit class JsonDecoderSyntax[F[_]](private val req: Message[F])(implicit F: JsonDecoder[F]) {
Copy link
Member

Choose a reason for hiding this comment

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

It's a little weird we've ended up with syntax in our instances, but that's not a new problem. Something to ruminate over, though.

object JsonDecoder {
def apply[F[_]](implicit ev: JsonDecoder[F]): JsonDecoder[F] = ev

implicit def impl[F[_]: Sync]: JsonDecoder[F] = new JsonDecoder[F] {
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about what other implementations could plausibly exist. I guess for the other Stream.Compilers, though you'd want a MonadError for Id and Pure. It's not a typeclass with laws, so I guess a constant decoder "works".

I get the aversion to Sync, but I need some help thinking about why it's good to pretend that this can't fail.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

A little worried about having two ways to do something, and offering no guidance to users which to pick. An example would be helpful. And this has made me pause and think about which implementations we might create based on other Stream.Compilers. But I think this is reasonable.

@ChristopherDavenport ChristopherDavenport merged commit b5f9543 into http4s:master Nov 26, 2019
@kubukoz
Copy link
Contributor

kubukoz commented Mar 25, 2021

I think this isn't being used in the client, do you folks think we could get that in 1.0.0? Happy to help, just wondering if there are any arguments against

@rossabaker
Copy link
Member

I've never used it, so I can't say how well it has aged. But symmetry seems good. If it has worked out well for people, I'd be 👍.

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

5 participants