-
Notifications
You must be signed in to change notification settings - Fork 922
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
lib/template: allow range over number #1566
Conversation
lib/template/exec.go
Outdated
if intVal <= 0 { | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather raise a runtime error in this case. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fine with me, but I think it might not be so user friendly if the value of n
is a variable that the user does not know the value, like a count from DB
Perhaps < 0
could be a runtime error but = 0
could remain a simple break, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think range 0
should be permitted, but negative is nonsensical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
lib/template/exec.go
Outdated
if intVal <= 0 { | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Why is this necessary when we already have |
It provides, imo, a better syntax. Also, it does not require allocating a slice, thus using less memory.
I don't think so. Seq still allows you to start from a value other than 0. This PR is inspired on the proposal to range over n in go itself. |
This PR adds the ability to range over a number (i.e. ints and uints) in template.
Should print
0011
Should print
01
Should print
empty
Should throw an error