You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We would perhaps soon have the opportunity to introduce subscripts as an alternative to operators. Here are some hasty thoughts:
Pros:
Can record A LOT of metadata using implicit parameters
Perhaps looks nicer
Cons:
Requires some redesign (although I've wanted to move in this direction anyways)
Requires JSON type, does not work with Any. In a lot of ways this makes sense though.
I'm pretty sure this would work:
letv:String?=root["a"]["b"]?["c"]
a and b are allow null, c does not allow null
If you want "c" to allow null, you'd have to mark it explicitly with another syntax. Perhaps with
["key".allow(.null,.missingKey,...)]
There is a choice here whether to have all subscripts returning JSON structs, or whether to construct KeyPaths for as long as possible. I don't think there is an obvious advantage to any; try-catch-path-appending shenanigans are unavoidable, and being able to construct KeyPaths is nice.
With conditional protocol conformance, the need to generate overloads would go a way, so it would probably be easy to keep supporting the operator syntax.
The text was updated successfully, but these errors were encountered:
Anviking
changed the title
Subscripts
Subscripts as alternative to operators
Mar 1, 2017
We would perhaps soon have the opportunity to introduce subscripts as an alternative to operators. Here are some hasty thoughts:
Pros:
Cons:
I'm pretty sure this would work:
If you want "c" to allow null, you'd have to mark it explicitly with another syntax. Perhaps with
There is a choice here whether to have all subscripts returning
JSON
structs, or whether to constructKeyPath
s for as long as possible. I don't think there is an obvious advantage to any; try-catch-path-appending shenanigans are unavoidable, and being able to constructKeyPath
s is nice.With conditional protocol conformance, the need to generate overloads would go a way, so it would probably be easy to keep supporting the operator syntax.
The text was updated successfully, but these errors were encountered: