Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pfftdammitchris/7a508264bdb535c729519a4faf3d388d to your computer and use it in GitHub Desktop.
Save pfftdammitchris/7a508264bdb535c729519a4faf3d388d to your computer and use it in GitHub Desktop.
class CumulativeSum {
constructor() {
this._executor = null
}
get executor() {
if (!this._executor) return (val) => val
return this._executor
}
set executor(fn) {
this._executor = fn
}
async add(currentValue) {
const result = await this.executor(currentValue, async (nextVal) => {
if (this.next) return this.next.add(nextVal)
return nextVal
})
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment