Skip to content
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

template: sort map keys before iteration? #2696

Closed
rsc opened this issue Jan 13, 2012 · 3 comments
Closed

template: sort map keys before iteration? #2696

rsc opened this issue Jan 13, 2012 · 3 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jan 13, 2012

Template already obtains a []reflect.Value giving the map keys
for a {{range}} over a map.  It would be a tiny amount more effort
to look at the key kind and sort (when comparable) before iteration,
using one of:

type rvs []reflect.Value
func (x rvs) Len() int { return len(x) }
func (x rvs) Swap(i, j int) { x[i], x[j] = x[j], x[i] }

type rvInts struct { rvs }
func (x rvInts) Less(i, j int) { return x.rvs[i].Int() < x.rvs[j].Int() }

type rvUints struct { rvs }
func (x rvUints) Less(i, j int) { return x.rvs[i].Uint() < x.rvs[j].Uint() }

type rvFloats struct { rvs }
func (x rvFloats) Less(i, j int) { return x.rvs[i].Float() < x.rvs[j].Float() }

type rvStrings struct { rvs }
func (x rvStrings) Less(i, j int) { return x.rvs[i].String() < x.rvs[j].String() }
@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 1:

Labels changed: added priority-go1.

@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 2:

Owner changed to builder@golang.org.

@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 3:

This issue was closed by revision a5950df.

Status changed to Fixed.

@rsc rsc added fixed labels Jan 13, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants