Skip to content

Instantly share code, notes, and snippets.

@zwaldowski
Created June 29, 2022 13:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
@resultBuilder
struct ArrayBuilder<Element> {
static func buildExpression(_ expression: Element) -> [Element] {
[ expression ]
}
static func buildBlock(_ elements: [Element]...) -> [Element] {
elements.flatMap { $0 }
}
static func buildOptional(_ elements: [Element]?) -> [Element] {
elements ?? []
}
static func buildEither(first component: [Element]) -> [Element] {
component
}
static func buildEither(second component: [Element]) -> [Element] {
component
}
}
@ArrayBuilder<Int> var bestNumbers: [Int] {
16
42
9001
if Bool.random() {
69
} else {
68
}
if Bool.random() {
101
}
}
print(bestNumbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment