Created
August 17, 2020 13:47
-
-
Save Sajjon/2b308ca31918c573128905dbe376295b to your computer and use it in GitHub Desktop.
@_functionBuilder support for Pipeline.
This file contains hidden or 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
// 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