-
-
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
Replace <| operator with generic subscript #488
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).
@@ -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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dis ugly
This is one short step away from dynamic member lookup which will be coming in Swift 4.2. Instead of |
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. |
This is to follow-up the [PR][] that removed `<|` operators from the code. [PR] thoughtbot#488
This is to follow-up the [PR][] that removed `<|` operators from the code. [PR]: thoughtbot#488
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).