-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
tpl/math: Allow variadic math functions to take slice args #11030
Comments
In retrospect, we should have:
Excel has Items 2-4 would be backwards compatible. Thoughts? |
I'm a little slow tonight, but why couldn't we make {{ math.Add 6 7 42 }} Both work? |
My thinking was:
When building a slice for |
Sure, but it shouldn't be too hard to expand on that logic and define args as either So I agree that we should do what this issue describes, but we cannot (and I don't see why we would have to) remove the option to say e.g. |
If I understand correctly, you are suggesting:
I find that confusing for a couple of reasons:
My preference is to:
This is backwards compatible. |
I think this is easier to reason about if you say that if 1 argument and that argument is a slice, then "unpack" it and then apply regular validation rules (which is a way of simulating varg with slice). With that {{ math.Add (slice 6) }} => {{ math.Add 6 }} => error (this is the current behavior, needs > 1 arg) I'm not sure your examples above ala {{ math.Min (slice 6) (slice 7) }} Makes much sense to me. I think we should focus on the main problem in this issue: That it's not currently a way to do |
Sorry, I'm not making myself clear.
I don't know how many pages are in the collection. Could be 0, 1, 2, etc. The functions should not error with 1 arg. |
To get the discussion back on track. I agree about what you say here:
|
…Product, math.Sum * Update math.Min and math.Max to allow 1 or more args, either scalar or slice, or combination of the two * Add math.Sum (allow 1 or more args, either scalar or slice, or combination of the two) * Add math.Product (allow 1 or more args, either scalar or slice, or combination of the two) Fixes gohugoio#11030
…Product, math.Sum * Update math.Min and math.Max to allow 1 or more args, either scalar or slice, or combination of the two * Add math.Sum (allow 1 or more args, either scalar or slice, or combination of the two) * Add math.Product (allow 1 or more args, either scalar or slice, or combination of the two) Fixes gohugoio#11030
…Product, math.Sum * Update math.Min and math.Max to allow 1 or more args, either scalar or slice, or combination of the two * Add math.Sum (allow 1 or more args, either scalar or slice, or combination of the two) * Add math.Product (allow 1 or more args, either scalar or slice, or combination of the two) Fixes #11030
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
#10638 changed
add
,sub
,mul
,div
,main
, andmax
into variadic functions. So you can do this:I'm finding this would be much more useful:
And these should be valid as well:
I suppose we should do the same with
math.Sub
andmath.Div
.The recently implemented
urls.PathJoin
follows this model.They should still throw an error with a single arg. For example
The text was updated successfully, but these errors were encountered: