Created
April 19, 2021 04:18
-
-
Save pfftdammitchris/7a508264bdb535c729519a4faf3d388d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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