Skip to content

Instantly share code, notes, and snippets.

@mortdeus
Created November 3, 2013 04:45
Show Gist options
  • Select an option

  • Save mortdeus/7286854 to your computer and use it in GitHub Desktop.

Select an option

Save mortdeus/7286854 to your computer and use it in GitHub Desktop.
Interesting little construct that matches a Map to a Slice.
package main
import "fmt"
func main() {
v := map[int]string{
3: "Quz",
0: "Foo",
2: "Baz",
1: "Bar",
}
t := make([]string, 0)
for {
if len(t) < len(v) {
t = append(t, v[len(t)])
continue
}
break
}
fmt.Println(t)
for k, v := range v {
fmt.Print(k, ":", v, " ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment