Skip to content

Instantly share code, notes, and snippets.

@Sajjon
Created August 17, 2020 13:47
Show Gist options
  • Save Sajjon/2b308ca31918c573128905dbe376295b to your computer and use it in GitHub Desktop.
Save Sajjon/2b308ca31918c573128905dbe376295b to your computer and use it in GitHub Desktop.
@_functionBuilder support for Pipeline.
// MARK: FunctionBuilder
@_functionBuilder
struct BuildPipeline {
static func buildBlock<A>(_ a: A) -> Pipeline<A.Input, A.Output>
where
A: Job
{
Pipeline(description: descriptionOf(jobs: [a])) { input in
try a.work(input: input)
}
}
static func buildBlock<A, B>(_ a: A, _ b: B) -> Pipeline<A.Input, B.Output>
where
A: Job, B: Job,
A.Output == B.Input
{
Pipeline(description: descriptionOf(jobs: [a, b])) {
try $0 |> a |> b
}
}
static func buildBlock<A, B, C>(_ a: A, _ b: B, _ c: C) -> Pipeline<A.Input, C.Output>
where
A: Job, B: Job, C: Job,
A.Output == B.Input,
B.Output == C.Input
{
Pipeline(description: descriptionOf(jobs: [a, b, c])) {
try $0 |> a |> b |> c
}
}
static func buildBlock<A, B, C, D>(_ a: A, _ b: B, _ c: C, _ d: D) -> Pipeline<A.Input, D.Output>
where
A: Job, B: Job, C: Job, D: Job,
A.Output == B.Input,
B.Output == C.Input,
C.Output == D.Input
{
Pipeline(description: descriptionOf(jobs: [a, b, c, d])) {
try $0 |> a |> b |> c |> d
}
}
// etc... all the way up to 10 different jobs...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment