Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sum,sumBy): add a feature handling bigint values to original library #766

Closed
wants to merge 6 commits into from

Conversation

dayongkr
Copy link
Contributor

Overview

I added the feature to original library.

If the array is empty, it is impossible to distinguish between bigint and number, so I implemented it to always return 0 when the array is empty.

Therefore, in the overloading signature of sumBy, it is specified that if the return type of getValue is bigint, the function may return either a bigint or a number.

close #742

@dayongkr dayongkr requested a review from raon0211 as a code owner October 27, 2024 05:50
Copy link

vercel bot commented Oct 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 30, 2024 1:33am

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.13%. Comparing base (247fb77) to head (0be3f57).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #766   +/-   ##
=======================================
  Coverage   99.13%   99.13%           
=======================================
  Files         296      296           
  Lines        2645     2649    +4     
  Branches      772      774    +2     
=======================================
+ Hits         2622     2626    +4     
  Misses         22       22           
  Partials        1        1           

@dayongkr
Copy link
Contributor Author

dayongkr commented Nov 1, 2024

After discussing it in the Discord channel, we decided not to support BigInt in our sum and sumBy functions.

Instead, we’ll implement separate functions, such as sumBigInt and sumBigIntBy.

Here’s why:

We want to maintain a property like sum([a,b,c]) + sum([d,e,f]) === sum([a,b,c,d,e,f]).
However, with BigInt support, this property would break.
For example, sum([]) + sum([1n,2n]) would throw an error, while sum([...[], ...[1n,2n]]) would return 3n, thus violating the intended property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sum() should allow bigint
2 participants