feat: add Pipeline function

This commit is contained in:
dudaodong committed 2022-10-15 12:29:47 +08:00
1 parent 1ccf0af2b3
commit b8563ed646
3 files changed
+32

No files matched your search

+12
View File
@@ -113,3 +113,15 @@ func Schedule(d time.Duration, fn any, args ...any) chan bool {
return quit
}
// Pipeline takes a list of functions and returns a function whose param will be passed into
// the functions one by one.
func Pipeline[T any](funcs ...func(T) T) func(T) T {
return func(arg T) (result T) {
result = arg
for _, fn := range funcs {
result = fn(result)
}
return
}
}