Skip to content

Instantly share code, notes, and snippets.

@MuizMahdi
Created November 23, 2020 23:23
Show Gist options
  • Save MuizMahdi/e62dab74584042206950ce37a12ed985 to your computer and use it in GitHub Desktop.
Save MuizMahdi/e62dab74584042206950ce37a12ed985 to your computer and use it in GitHub Desktop.
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