You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, {{ range foo := someSlice }} will set both . and foo to the element value of the current iteration. To make this one-var syntax more useful, I would like range to set foo to the index of the element instead.
Iterating over a map with a one-variable assignment would set that var to the key of the current element.
Iterating over a channel with a one-variable assignment would set that var to the current element as before, since channel element values don't have a key or index.
{{ range foo, bar := someSlice }} would still set foo to the index, and bar to the element itself.
This is of course a breaking change, so definitely a major version bump.
The text was updated successfully, but these errors were encountered:
sauerbraten
changed the title
Range over slice with single var assignment should set the var to the index
Range over slice/map with single var assignment should set the var to the index/key
Jul 2, 2020
…osesCloudyKit#158)
basically, if the ranger provides both a range value as well as an index, the one-var syntax sets that var to the index. if the ranger provides no index, one-var syntax will give you the value. this way, Jet's range now behaves like Go's range for maps, slices, arrays, and channels.
…oses#158)
basically, if the ranger provides both a range value as well as an index, the one-var syntax sets that var to the index. if the ranger provides no index, one-var syntax will give you the value. this way, Jet's range now behaves like Go's range for maps, slices, arrays, and channels.
Currently,
{{ range foo := someSlice }}
will set both.
andfoo
to the element value of the current iteration. To make this one-var syntax more useful, I would like range to setfoo
to the index of the element instead.Iterating over a map with a one-variable assignment would set that var to the key of the current element.
Iterating over a channel with a one-variable assignment would set that var to the current element as before, since channel element values don't have a key or index.
{{ range foo, bar := someSlice }}
would still setfoo
to the index, andbar
to the element itself.This is of course a breaking change, so definitely a major version bump.
The text was updated successfully, but these errors were encountered: