Created
November 23, 2020 23:23
-
-
Save MuizMahdi/e62dab74584042206950ce37a12ed985 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
interface Stage<I, O> { | |
O process(I input); | |
} | |
class Pipeline<I, O> { | |
private final Stage<I, O> currentStage; | |
Pipeline(Stage<I, O> currentStage) { | |
this.currentStage = currentStage; | |
} | |
<K> Pipeline<I, K> addStage(Stage<O, K> newStage) { | |
return new Pipeline<>(input -> newStage.process(currentStage.process(input))); | |
} | |
O execute(I input) { | |
return currentStage.process(input); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment