vitaly-t / iter-ops

Basic operations on iterables
https://vitaly-t.github.io/iter-ops
MIT License
136 stars 5 forks source link

feat: add async callback support to operator `reduce` #188

Closed RebeccaStevens closed 1 year ago

RebeccaStevens commented 1 year ago

fix #181

codecov-commenter commented 1 year ago

Codecov Report

Base: 99.60% // Head: 99.60% // Increases project coverage by +0.00% :tada:

Coverage data is based on head (64163f4) compared to base (a47f77d). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #188 +/- ## ======================================= Coverage 99.60% 99.60% ======================================= Files 45 45 Lines 1510 1517 +7 Branches 315 316 +1 ======================================= + Hits 1504 1511 +7 Misses 2 2 Partials 4 4 ``` | [Impacted Files](https://codecov.io/gh/vitaly-t/iter-ops/pull/188?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [src/ops/reduce.ts](https://codecov.io/gh/vitaly-t/iter-ops/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29wcy9yZWR1Y2UudHM=) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

vitaly-t commented 1 year ago

In #181, I mentioned that we might allow the initial value to be a promise. And in the one-line solution that I gave, it would handle a Promise as the initial value.

In your solution, you do not allow it. Could you, please share your thoughts on why not?

RebeccaStevens commented 1 year ago

Adding support for a promise as the initial value was a little bit tricker but I've added it now. The one-line solution you gave was close to what was needed but didn't quite work. (The first argument passed to the callback, should be the awaited value, not the promise itself)

vitaly-t commented 1 year ago

I have refactored out an extraneous promise there. I hope you don't mind :smile: