> On 14 Apr 2016, at 21:36, John McCall <rjmcc...@apple.com> wrote:
> 
> No, you just need Tree to conform to both ArrayLiteralConvertible and 
> IntegerLiteralConvertible, and it implements the latter by building a Value 
> out of it.

You mean this:

public enum IntTree {
        case Leaf(Int)
        case Branches([IntTree])
}

extension IntTree : ArrayLiteralConvertible {
        public init(arrayLiteral elements: IntTree...) {
                self = .Branches(elements)
        }
}

extension IntTree : IntegerLiteralConvertible {
        public init(integerLiteral value: IntegerLiteralType) {
                self = .Leaf(value)
        }
}

let tree: IntTree = [[], 1, [2, 3], [[4, 5], [6, 7], [8, 9]]]

> you'll simply have to make your Tree less generic


Yep, that’s the rub… With generic trees you can express yourself freely, 
whether you feel like:

import SpriteKit

let actionTree: Tree<SKAction> = [
        ◊.waitForDuration(1),
        [
                ◊.fadeInWithDuration(1),
                ◊.scaleTo(1, duration: 1)
        ],
        ◊.playSoundFileNamed("TaDa", waitForCompletion: false)
]

… or:

let johnny: DictionaryTree<String, JSONValue> =
[
        "name": ◊"Johnny Appleseed",
        "age": ◊25,
        "address": [
                "house_number": ◊21,
                "street": ◊"2nd Street",
                "city": ◊"New York"
        ]
]

I’d just love to get rid of that prefix operator…

milos









_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to