[swift-evolution] TreeLiteralConvertible
Milos Rankovic
milos at milos-and-slavica.net
Fri Apr 15 14:28:35 CDT 2016
> On 15 Apr 2016, at 19:54, Haravikk <swift-evolution at haravikk.me> wrote:
>
> While the original post is an interesting way to define this structure, I think a specialised type is required to really capture this usefully.
Sure. I never meant it as a replacement. It was a response to someone’s challenge whether one could express a piece of JSON data as a literal using the two example tree enums. The two protocols I’m proposing, however, could be implemented by many different kind of tree types, some of which could just as well have properties that fit JSON perfectly. It would then be a joy instantiating short JSON snippets as literals.
Still, as John anticipated, I could get this to compile too (keeping in mind that the lift operator ◊ would disappear if we get the two proposed protocols):
let johnny: DictionaryTree<String, JSONValue> =
[
"children": ◊["George", "Ann", "Percy"],
"phoneNumbers": ◊[
◊[
"type": ◊"home",
"number": ◊"212 555-1234"
],
◊[
"type": ◊"office",
"number": ◊"646 555-4567"
],
]
]
… where:
enum JSONValue {
case Text(String)
case Array([JSONValue])
indirect case Object(DictionaryTree<String, JSONValue>)
}
milos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160415/c115781b/attachment.html>
More information about the swift-evolution
mailing list