-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: Support custom collection types in template range #30541
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
Comments
@bep is this a proposal, or a feature request? |
It's a proposal for a feature request. I have not studied the definitions to know where the lines go. I don't see how this feature could break anything, but it probably needs some more thought before it's implemented (mainly to get the interface right; it probably also need a method to get one item by index (so it can be used by the |
Go templates are modeled on Go itself as far as what is provided. We should figure out what the story is for generalized iteration in Go's own |
Can close this. If we do make a change for Go itself we will remember to come back to template. |
FYI I’ve been thinking about generalized range loops at the Go language level. I plan to open an issue for discussion at some point soon; the delay has been that I don’t yet have a proposal to put on the table that I really like. But it seems I should start a place to have that discussion, anyway. |
The only loop construct available in Go templates is the
range
keyword, which currently is restricted to an array, slice, map, or a channel.It would be really useful if
range
also could support customlist
andmap
types, as that would enable:The
immutable
library above has outlined some nice interfaces that could be inspirational, the core part ofMapIterator
included as an example:I'm confident that you will get many hands raised if you ask around "do Go templates need a more powerful loop construct?" The alternative to this proposal would possibly be to add a
for
keyword, but I think it would be better to leave the complexities to the Go code.The text was updated successfully, but these errors were encountered: