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
Specific List functions can accept 0 elements #2351
Conversation
🦋 Changeset detectedLatest commit: 85d81c8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2351 +/- ##
=======================================
Coverage 71.65% 71.66%
=======================================
Files 111 111
Lines 5704 5706 +2
Branches 1091 1093 +2
=======================================
+ Hits 4087 4089 +2
Misses 1610 1610
Partials 7 7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sum
and product
, there's a slight risk that in the future we'll have to deal with ambiguity because of polymorphism: we could decide to add sum(string[])
or sum(dist[])
, and then the result of sum([])
becomes unclear.
This could be bad if the array is generated dynamically, and especially because of interactions with the type inference and compile-time polymorphic dispatch.
Consider this code:
sumArrays(arrs) = arrs -> map({|arr| sum(arr)})
sumArrays([
["foo", "bar"],
[] // imagine that this was obtained by calling another function that does `filter` at runtime
])
Now, if sum
is polymorphic, but we also have sum([])
defined to be 0
, then the result of sumArrays
will be either ["foobar", 0]
or ["foobar", ""]
.
["foobar", ""]
result could happen in this case if the interpreter would detect that sumArrays
accepts an array of arrays of strings, and so every sum
call is over an array of strings.
So it's going to be a minor breaking change, when/if we get there.
Number.sum, product, sort, cumsum, cumprod, should all accept lists with 0 elements
This closes #2349