Last active
August 19, 2019 05:40
-
-
Save kgn/38334d387ffb61a8c4ebe4a059d2f45f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@_functionBuilder | |
struct PeopleBuilder { | |
static func buildBlock(_ people: Person...) -> [Person] { | |
return people | |
} | |
} | |
struct Table { | |
let people: [Person] | |
// For blocks that return just 1 Person object | |
init(@PeopleBuilder _ builder: () -> Person) { | |
self.people = [builder()] | |
} | |
// For blocks that return multiple Person objects | |
init(@PeopleBuilder _ builder: () -> [Person]) { | |
self.people = builder() | |
} | |
} | |
Table { | |
Person("Mr. Ed Ford", .chicken) | |
} | |
Table { | |
Person("Mr. John Smith", .beef) | |
Person("Mrs. Jane Smith", .chicken) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment