Skip to content

[Suggestions] add sum function to math #44674

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

Closed
erf opened this issue Jan 15, 2021 · 3 comments
Closed

[Suggestions] add sum function to math #44674

erf opened this issue Jan 15, 2021 · 3 comments

Comments

@erf
Copy link

erf commented Jan 15, 2021

Have you considered adding a sum(a, b) function to the mathpackage for adding two numbers together.

Example implementation:

T sum<T extends num>(T lhs, T rhs) => (lhs + rhs) as T;

Nice to to have if you'd like to e.g. list.reduce(sum)

@lrhn
Copy link
Member

lrhn commented Jan 15, 2021

Dart has fairly short first class function expressions, so list.reduce((a, b) => a + b) has been considered usable and readable enough that we don't need extra top-level functions that emulate the binary operators.

If we get an even shorter syntax for simple functions (see dart-lang/language#8), perhaps like =>_1+_2, then it would be even briefer: list.reduce(=>_1+_2). Having to give that a name, and take up space in the global namespace, feels like unnecessary overhead.

@erf
Copy link
Author

erf commented Jan 15, 2021

Ok, thanks. I like the shorthand syntax, but the link seem to point to wrong issue?

@erf erf closed this as completed Jan 15, 2021
@lrhn
Copy link
Member

lrhn commented Jan 15, 2021

Fixed link, forgot I wasn't in the language repo.

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

No branches or pull requests

2 participants