Open acatl opened 5 years ago
any ideas? is this bad idea? maybe the name of the methods is not the best? can we improve?
but testing becomes annoying and we end up having a method signature that is not the right one for the purpose of the function.
I'm not sure that I understand what you mean, since all reducer functions have the same signature, whether or not the function uses every argument.
What do you think about calling reducer functions with the accumulator set as this
?
mainly ive seen many functions created that manipulate data that if created as a function with only the arguments needed they would be more reusable and have less coupling with datapoint’s reducer api.
Problem description:
More than often we find ourselves writing reducer functions that only need either the
input
or theaccumulator
parameters. The result is functions such as:Very often this caught by PRs and asked the devs to refactor methods to only accept the right param, or we end up ignoring the function param signature and just let it be.
but testing becomes annoying and we end up having a method signature that is not the right one for the purpose of the function.
Suggested solution:
export from datapoint object 2 function:
These methods would allow the previous methods to be written as:
On this case, the main methods only are expecting the right parameters which will make unit testing easier, and the augmented functions can have the name Reducer as part of their name to be more expressive of what they do.