Created
June 29, 2022 13:44
-
-
Save zwaldowski/8a1258765fe57aaa043f6e3021e00096 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
@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