-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
text/template: range over func and int #66107
Comments
I think we need to define some semantics and I think there are likely open questions (and in part without obvious answers). First, obviously, there are one- and two-variable iterators. What should Then we have the Lastly: If calling a function or method in a template (either by using a function name as an action, or using the AIUI it is not entirely clear how error handling with iterators will work, really. For example, if you have an iterator that reads lines from a file, parsing each line into a struct, there are two ways it can fail: 1. a An alternative I could imagine is to say that you can If we were to go with that suggestion, we would probably want to make At least those are my thoughts. There are probably other ways to define these semantics. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
Regarding the semantics, it seems like we should require that if the iterator yields 2 values, then you have to use the {{range $x, $y := $f}} form. |
This proposal has been added to the active column of the proposals project |
It would be consistent to allow ranging over int as well. |
This seems fine but we should wait for #66056 to help with the implementation. |
Based on the discussion above, this proposal seems like a likely accept. The proposal is to allow range over func and int the same as in Go. |
No change in consensus, so accepted. 🎉 The proposal is to allow range over func and int the same as in Go. |
Fixes golang#66107 Change-Id: If3e503efca200aa86463c9d27d06986b03c0d638
Fixes golang#66107 Change-Id: If3e503efca200aa86463c9d27d06986b03c0d638
Change https://go.dev/cl/596956 mentions this issue: |
Fixes golang#66107 Change-Id: If3e503efca200aa86463c9d27d06986b03c0d638
Fixes golang#66107 Change-Id: I2fcd04bebe80346dbd244ab7ea09cbe6010b9d8e GitHub-Last-Rev: da1a7ac GitHub-Pull-Request: golang#68329
For golang#66107 Change-Id: I19b466e3fb17557cf4f198b7fd8c13e774d854b1
For #66107 Change-Id: I2fcd04bebe80346dbd244ab7ea09cbe6010b9d8e GitHub-Last-Rev: 5ebf615 GitHub-Pull-Request: #68329 Reviewed-on: https://go-review.googlesource.com/c/go/+/596956 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
Change https://go.dev/cl/615095 mentions this issue: |
Fixes golang#66107 Change-Id: I19b466e3fb17557cf4f198b7fd8c13e774d854b1
Fixes golang#66107 Change-Id: I19b466e3fb17557cf4f198b7fd8c13e774d854b1
Proposal Details
The Rangefunc change is adding support for range on custom functions.
The text/html template std library has a range operator which is documented as
The template library should support range over a function. The use case is wanting to return a Rangefunc on top of a sql rows iterator which can be passed to the template for text generation.
This was the discussion in the group https://groups.google.com/g/golang-nuts/c/_lykyoQHmGc
The text was updated successfully, but these errors were encountered: