-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
RFC: Renaming (or removing) the <|
family of operators
#479
Comments
I'm 👍 on the general idea. How about using a subscript? That seems like it'd be very readable and obvious to everyone, no matter their experience level. I'm not sure how to handle optionals though… Maybe a label? extension User: Argo.Decodable {
static func decode(_ json: JSON) -> Decoded<User> {
return curry(self.init)
<^> json["id"]
<*> json["userinfo", "name"] <|> json["name"]
<*> json[maybe: "email"]
}
} Or what if you got rid of the concept of |
I was actually talking about this at lunch and meant to come back in to propose that exact subscripting API. I was thinking
Not sure that I follow this. Are you suggesting that we push people towards using |
This. If |
Ah, sure. Conditional conformance. My brain hasn't fully groked the ways that will clean up our API yet. That passes my brain typechecker. I'd definitely be interested in trying to simplify our API as much as possible. In theory there's a benefit to explicitly marking optional properties, but I'm not sure how much the benefit outweighs the mental overhead. Probably not much. |
Doing this in #488 |
I'd like to think about at least renaming, or maybe even removing, the
<|
family of operators in Argo. I think this falls in line with the goals for the (theoretical) next release of Argo, where we're going to be renaming large parts of the lib in order to remove ambiguity or clarify library intent (see #474 and #473). There are a couple of reasons for renaming these operators:<|
for right-to-left function application in languages like F#. Since becoming aware of this, I've seen|>
used more and more for left-to-right function application, and the fact that our operator conflicts with this existing expectation bothers me, and seems like it could lead to confusion.JSON
instances can to some fairly gnarly code that's really hard to read. Many times, this is due to ambiguous precedence between all of the different operators needed to fully implement a non-trivial decoder.<|
is incredibly specialized, and only really works with the shapeJSON -> String -> Decoded<T>
. This means its use is limited, and could probably be replaced by a method onJSON
itself.I'd propose making the drastic change of removing the
<|
family of operators in the next release of Argo in favor of a named method (JSON.extract
). For the sake of discussion, here's a sample of the before/after for one of our decode methods in our test suite:The optional method name is an interesting problem to need to solve, I'm not confident that
extractOpt
is the right choice there. I'd love to doextract?
but that's not valid swift. Also, of note: this will be made simpler by the fact that with Swift 4.1 (which we should target for these changes) we'll be able to remove the collection operators (<||
) from the lib anyway.The text was updated successfully, but these errors were encountered: