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

Any plans to addsum helper? #40

Closed
balinterdi opened this issue Nov 15, 2016 · 7 comments · Fixed by #614
Closed

Any plans to addsum helper? #40

balinterdi opened this issue Nov 15, 2016 · 7 comments · Fixed by #614

Comments

@balinterdi
Copy link

I think having this could be useful:

(sum sectionTotal1 sectionTotal2)
@skeate
Copy link
Contributor

skeate commented Nov 15, 2016

Is there any appreciable difference between that and add?

@balinterdi
Copy link
Author

@skeate No, there is none, I just did not see the add helper, sorry :)

@bj-mcduck
Copy link

@skeate, can you use the add helper for an array? {{add thisItem.arrayOfNumbers}}

A sum helper would be great for this, if add doesn't already do this.

@bj-mcduck
Copy link

bj-mcduck commented Jan 31, 2017

I just tried this with ember-composable-helpers, the following didn't work:

{{add (map-by 'clientPriceCents' order.orderItems)}}

If there were some kind of splat method widely available the add method would be fine.
I think having a proper sum helper would be helpful though.

@bj-mcduck
Copy link

If I make a PR, would it be welcomed?

@skeate
Copy link
Contributor

skeate commented Jan 31, 2017

This would be trivial with a spread operator, which is in RFC: emberjs/rfcs#184

though that appears to be more focused on named arguments, and thus (if they don't see a use case for it) might not be implemented to support arrays.

I still don't agree with adding a separate sum helper, especially if it's not just an alias to add. Having to check the docs all the time to remember which was which would be a pain.

This should be doable with ember-composable-helpers, though. Perhaps {{reduce add (map-by 'clientPriceCents' order.orderItems}}? (can't test right now to see if that actually works)

One possibility for this addon would be to just do some typechecking. If we have one param and it's an array, return the sum of that. That does lead to "well why not flatten any arrays passed", and suddenly we're in space where behavior is not completely intuitive.

@bj-mcduck
Copy link

I was trying to test this out, but couldn't get it to work as you mentioned. Shelfing it for now though as I no longer need it for my use-case.
Thanks for the ideas! Hopefully it'll help people looking to do the same :)

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 a pull request may close this issue.

3 participants