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

fix types in sumBy to enable summing a list full of doubles #71

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

matthias-prevost
Copy link
Contributor

@matthias-prevost matthias-prevost commented Mar 8, 2024

What was the problem ?

When using sumBy on a list where the mapper function would return only doubles, the method throws an error.
The error is :

type 'int' is not a subtype of type 'double' in type cast
package:fast_immutable_collections/src/base/iterable_extension.dart 139:18  FicIterableExtension.sumBy
test/base/iterable_extension_test.dart 30:38                                main.<fn>

Code in error :

  N sumBy<N extends num>(N Function(T element) mapper) {
    N result = 0 as N; // <- the code that throws the error
    ...
  }

Step to reproduce :

[1.5, 2.5, 3.3, 4.3, 5.3].sumBy((e) => e)

Reason :
If the list only has double, type N is double and the type cast of 0 fails

@matthias-prevost matthias-prevost marked this pull request as ready for review March 8, 2024 10:13
@marcglasberg marcglasberg merged commit 7031482 into marcglasberg:master Mar 8, 2024
@marcglasberg
Copy link
Owner

@matthias-prevost Thank you!

Published: version 10.1.2

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.

2 participants