Closed tqma113 closed 2 years ago
It's hard to see the necessity to support custom counter callback in the use-case you shown above.
Just introduce a helper function for auto-calling next.
const autoPass = (f) => (input, next) => next(f(input))
const pipeline = createPipeline<number, number>()
const foo = (a: number) => a+1
const bar = (a: number) => a*2
const baz = (a: number) => a**2
pipeline.use(autoPass(foo))
pipeline.use(autoPass(bar))
pipeline.use(autoPass(baz))
pipeline.run(1) // 16
Or introduce createAutoPassPipeline()
for that.
const createAutoPassPipeline = () => {
const pipeline = createPipeline()
return {
use: f => {
pipeline.use((input, next) => next(f(input))
}
}
}
Another concern is that if we expose the counter under farrow-pipeline, the user almost can do everything even breaking the semantic of pipeline
Support to custom callback of Counter:
For now, it is stable:
Expect:
for more way to run middlewares.
If I can custom callback of Counter: