munificent / ui-as-code

Design work on improving Dart's syntax for UI code
BSD 3-Clause "New" or "Revised" License
121 stars 11 forks source link

Swift has implicit enums #7

Open kasperpeulen opened 6 years ago

kasperpeulen commented 6 years ago

About: https://github.com/munificent/ui-as-code/blob/master/ideas/implicit-enums.md

Swift has this feature already, it is quite popular I belief, so you may draw some inspiration from it.

It works for static members of classes, that return the same type as well as for enums.

class Fruit {
    static var apple = Fruit(name: "apple");
    static var banana = Fruit(name: "banana");

    var name: String;

    init(name: String) {
        self.name = name;
    }
}

func printFruit(fruit: Fruit) {
    print(fruit.name);
}

// .banana is here inferred as Fruit.banana
printFruit(fruit: .banana);
munificent commented 6 years ago

Thanks for the pointer!