Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmtszr committed Mar 18, 2023
1 parent 1ae2e60 commit 2774c35
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
.idea

# Test binary, built with `go test -c`
*.test
Expand Down
9 changes: 9 additions & 0 deletions pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pipeline

type Pipeline[K any] struct {
pipelineStepDelegate PipelineStepDelegate[K]
}

func (t Pipeline[K]) execute(context K) {
t.pipelineStepDelegate(context)
}
24 changes: 24 additions & 0 deletions pipeline_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pipeline

type PipelineBuilder[K any] struct {
steps []func(next PipelineStepDelegate[K]) PipelineStepDelegate[K]
}

func (t PipelineBuilder[K]) build() Pipeline[K] {
var step PipelineStepDelegate[K] = func(context K) {}
for i := len(t.steps) - 1; i >= 0; i-- {
step = t.steps[i](step)
}
return Pipeline[K]{
pipelineStepDelegate: step,
}
}

func (t PipelineBuilder[K]) usePipelineStep(step PipelineStep[K]) PipelineBuilder[K] {
t.steps = append(t.steps, func(next PipelineStepDelegate[K]) PipelineStepDelegate[K] {
return func(context K) {
step.execute(context, next)
}
})
return t
}
7 changes: 7 additions & 0 deletions pipeline_step.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pipeline

type PipelineStepDelegate[K any] func(context K)

type PipelineStep[K any] interface {
execute(context K, next func(context K))
}

0 comments on commit 2774c35

Please sign in to comment.