Replace <| operator with generic subscript - #488
Merged
Conversation
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).
gfontenot
commented
Apr 27, 2018
| */ | ||
| 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] |
tonyd256
approved these changes
Apr 27, 2018
Contributor
|
This is one short step away from dynamic member lookup which will be coming in Swift 4.2. Instead of |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
<|operator was necessary when we originally implemented Argo, but Swifthas 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 otherlanguages (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).