How to use function builder in Swift 5.1

Issue #361

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
protocol Task {}

struct Build: Task {}
struct Test: Task {}

@_functionBuilder
public struct TaskBuilder {
public static func buildBlock(_ tasks: Task...) -> [Task] {
tasks
}
}

public func run(@TaskBuilder builder: () -> [Task]) {
MyManager.run(tasks: builder())
}

public func run(@TaskBuilder builder: () -> Task) {
MyManager.run(tasks: [builder()])
}
1
2
3
4
run {
Build()
Test()
}

Read more

Comments