Created
February 6, 2025 19:35
-
-
Save McSlow/15a2a1bd72f5a43121f744de40d06659 to your computer and use it in GitHub Desktop.
Some Golang map experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"maps" | |
"slices" | |
"github.com/yassinebenaid/godump" | |
) | |
func main() { | |
// Stinkebatzen definition | |
type batzen struct { | |
color string | |
weight float64 | |
odor bool | |
} | |
dogpoo := batzen{ | |
weight: 5.6, | |
color: "yellowish", | |
odor: true, | |
} | |
catpoo := batzen{ | |
weight: 1.4, | |
color: "brown", | |
odor: false, | |
} | |
//associate a name with type of poo. intentionally unordered. | |
poomap := map[string]batzen{ | |
"catpoo": catpoo, | |
"dogpoo": dogpoo, | |
"asspoo": { | |
weight: 17.6, | |
color: "green", | |
odor: false, | |
}, | |
} | |
godump.Dump(poomap) | |
//sort da poo | |
keys := slices.Sorted(maps.Keys(poomap)) | |
//check order | |
fmt.Println(keys) | |
//iterate over it. Should be alphabetically sorted. | |
for _, v := range keys { | |
fmt.Println("Type:" + v) | |
fmt.Println("Color:" + poomap[v].color) | |
fmt.Println("----") | |
} | |
} |
Author
McSlow
commented
Feb 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment