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

sum: should work with empty collection #6373

Closed
Ducasse opened this issue May 19, 2020 · 7 comments
Closed

sum: should work with empty collection #6373

Ducasse opened this issue May 19, 2020 · 7 comments

Comments

@Ducasse
Copy link
Member

Ducasse commented May 19, 2020

#() sum: #linesOfCode should return 0.

right now it forces all the clients to check if the receiver is empty.
If we do not fix it, we should remove it and the user uses inject:into:

@Ducasse
Copy link
Member Author

Ducasse commented May 19, 2020

So just adding a self isEmpty ifTrue: [^ 0 ] would make it a lot more usable

@svenvc
Copy link
Contributor

svenvc commented May 19, 2020

Here we go again ...

(And it totally agree: https://en.wikipedia.org/wiki/Empty_sum)

@Ducasse
Copy link
Member Author

Ducasse commented May 19, 2020

thanks!
And we will fix it or remove it.
We can add sumNumbers: to help :)

@VincentBlondeau
Copy link
Contributor

What about adding sum:ifEmpty:?

#() sum: #linesOfCode ifEmpty: [0]

@bencoman
Copy link
Contributor

bencoman commented May 19, 2020

I find that Wikipedia article hard to follow. I think this is a simpler explanation in favour...
https://math.stackexchange.com/a/2310799

Mathematics Stack Exchange
Empty set is closed under addition. If not, there would be at least one element in the empty set whose addition with itself is not there, contradiction. Thus the result follows. This not a conventi...

@Ducasse
Copy link
Member Author

Ducasse commented May 20, 2020

Yes vincent I like your idea!
I think that it solves many problem.

@Ducasse Ducasse added the sprint label May 29, 2020
@MarcusDenker MarcusDenker added this to Ideas in Sprint via automation May 29, 2020
@olekscode olekscode moved this from Ideas to Working On in Sprint May 29, 2020
@olekscode olekscode moved this from Working On to Review Needed in Sprint May 29, 2020
@olekscode
Copy link
Member

This issue should be closed because the PR #6453 has been merged and the duplicated issue #6452 has been closed

Sprint automation moved this from Review Needed to DONE Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Sprint
  
DONE
Development

No branches or pull requests

6 participants