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

Replace <| operator with generic subscript #488

Merged
merged 1 commit into from
Apr 29, 2018

Conversation

gfontenot
Copy link
Collaborator

The <| operator was necessary when we originally implemented Argo, but Swift
has new capabilities now that reduce the need to use a custom operator.
Additionally, the operator spelling itself actually conflicts with prior-art
that we weren't aware of when we added it. Specifically, <| is used in other
languages (and sometimes in Swift) as a "pipe backwards" operator, with the
type (T -> U) -> T -> U.

Given these concerns, as well as the additional complexity around fine-tuning
the precedence so that it works in an obvious way, I think it makes sense to
remove the operator in favor of a generic subscript (which only just became
available in Swift 4).

The `<|` operator was necessary when we originally implemented Argo, but Swift
has new capabilities now that reduce the need to use a custom operator.
Additionally, the operator spelling itself actually conflicts with prior-art
that we weren't aware of when we added it. Specifically, `<|` is used in other
languages (and sometimes in Swift) as a "pipe backwards" operator, with the
type `(T -> U) -> T -> U`.

Given these concerns, as well as the additional complexity around fine-tuning
the precedence so that it works in an obvious way, I think it makes sense to
remove the operator in favor of a generic subscript (which only just became
available in Swift 4).
@@ -79,7 +79,7 @@ public func decode<T: Decodable>(_ object: Any) -> T? where T == T.DecodedType {
- returns: A `Decoded<T>` value where `T` is `Decodable`
*/
public func decode<T: Decodable>(_ dict: [String: Any], rootKey: String) -> Decoded<T> where T == T.DecodedType {
return JSON(dict as Any) <| rootKey
return JSON(dict as Any)[rootKey]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dis ugly

@gfontenot gfontenot merged commit 40f2e2e into master Apr 29, 2018
@gfontenot gfontenot deleted the gfontenot/operator-error branch April 29, 2018 15:06
@jshier
Copy link
Contributor

jshier commented Apr 29, 2018

This is one short step away from dynamic member lookup which will be coming in Swift 4.2. Instead of json["key"], it will allow json.key. It will be interesting to see if Argo can maintain it's error fidelity in that usage.

@gfontenot
Copy link
Collaborator Author

Oh man, I didn't even think about that. Great point! I wonder if we'd be able to support chaining for nested objects in that way as well? I'll be super interested in playing with this at some point.

eunikolsky added a commit to eunikolsky/Argo that referenced this pull request Sep 19, 2018
This is to follow-up the [PR][] that removed `<|` operators from the
code.

[PR] thoughtbot#488
eunikolsky added a commit to eunikolsky/Argo that referenced this pull request Sep 19, 2018
This is to follow-up the [PR][] that removed `<|` operators from the
code.

[PR]: thoughtbot#488
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.

3 participants