Skip to content

Miror clarifications to multi-arg example #84

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

Merged
merged 6 commits into from
Jul 13, 2020

Conversation

milesfrain
Copy link
Member

What does this pull request do?

Fixes broken example so it compiles.
Also adds some simplifications without detracting from what this section teaches.

Other Notes:

There are lots of other required fixes in these docs to change JsonDecodeError to String, but that should probably be another PR.

A bonus goal is to ensure inline snippets always compile by linking them to source files that are compiled as part of CI.

@thomashoneyman
Copy link
Contributor

This should be using JsonDecodeError (as is used with the latest version)

@milesfrain
Copy link
Member Author

Ah. Assumed this would be in the latest package set.

Override for reference:

let overrides =
  { argonaut =
      upstream.argonaut // { version = "v7.0.0" }
  , argonaut-core =
      upstream.argonaut-core // { version = "v5.0.2" }
  , argonaut-traversals =
      upstream.argonaut-traversals // { version = "v8.0.0" }
  , argonaut-codecs =
      upstream.argonaut-codecs // { version = "v7.0.0" }
  }

@thomashoneyman
Copy link
Contributor

thomashoneyman commented Jul 13, 2020

It’s about to be in the latest package set, but it isn’t yet.

@thomashoneyman
Copy link
Contributor

I’m not sure about changing to use Boolean instead of the three constructors; it seems like it introduces Boolean blindness here. What was your reasoning for the change?

@milesfrain
Copy link
Member Author

To address boolean blindness, would it be clearer to use newtype Following = Following Boolean?

When reading the original type, I kept misinterpreting who was doing the following (even with the comments). The way it read to me is that the Author is either You or a potential "follower".
Duplicating the String also seems less ideal, for example updating that type to Name would require changes to multiple lines.

README.md Outdated
| author == username -> Right You
-- user is not the author, or no one is logged in, so use the `following` flag
| otherwise -> Right $ Other author following
Nothing -> Left $ Named "Username" MissingValue
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if Named is the right error to use here. It certainly doesn't seem like AtKey is correct either.

Copy link
Contributor

@thomashoneyman thomashoneyman Jul 13, 2020

Choose a reason for hiding this comment

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

This isn't quite right; what this example is (supposed to be) getting at is that the Maybe Username argument represents the logged-in user, if there is one.

If it's a Just then someone is logged in, so we check to see if the logged-in person is the author; if they are the same, then we can return You. If they are not the same, then we can return Other and check the following flag.

If it's a Nothing then no one is logged in. In that case the viewer of the article isn't following the author of the article (because they can't be). So following should be false, and we can set the return value to Other author false.

None of these cases should produce an error.

Maybe this could be cleaned up to better represent the idea that you can have your decoding function depend on an argument without getting too bogged down in the details.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the point of confusion for me (beyond the initial package mismatch build errors) is that otherwise was used outside of the guard.
I'll make another PR to restore this as close as possible to the original example.

@milesfrain milesfrain changed the title Fix and simplify multi-arg example Miror clarifications to multi-arg example Jul 13, 2020
README.md Outdated
@@ -440,7 +440,7 @@ type BlogPost =
}
```

Our API tells us the author of the blog post as a string and whether we follow them as a boolean. This admits more cases than are actually possible -- you can't follow yourself, for example -- so we are more precise and model an `Author` as a sum type.
Our API tells us the author of the blog post is a `String` and whether we follow them is a `Boolean`. This admits more cases than are actually possible -- you can't follow yourself, for example -- so we are more precise and model an `Author` as a sum type.
Copy link
Member Author

Choose a reason for hiding this comment

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

I can see the original phrasing making more sense if "tells" is replaced with "sends".

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, "sends" is a better word here.

@milesfrain
Copy link
Member Author

A bit of a goose chase with this one. Should be good now.

@thomashoneyman thomashoneyman merged commit 377aaf0 into purescript-contrib:master Jul 13, 2020
@milesfrain milesfrain deleted the patch-2 branch July 13, 2020 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants