Skip to content

Instantly share code, notes, and snippets.

@pedrobertao
Created August 31, 2023 09:36
Show Gist options
  • Save pedrobertao/5d11c8ff0f3de6f8878640620ea9f439 to your computer and use it in GitHub Desktop.
Save pedrobertao/5d11c8ff0f3de6f8878640620ea9f439 to your computer and use it in GitHub Desktop.
maps package in golang
package main
import (
"fmt"
"golang.org/x/exp/maps"
)
func main() {
m := map[string]string{
"name": "Pedro",
"age": "20",
}
m2 := map[string]string{
"name": "Pedro",
"age": "20",
}
m3 := make(map[string]string)
// Equal and Equal Func
r := maps.Equal(m, m2)
r2 := maps.EqualFunc(m, m2, func(s1, s2 string) bool {
return m["name"] == m2["name"] && m["age"] == m2["age"]
})
fmt.Println("Equal: ", r)
fmt.Println("Equal Func: ", r2)
// Cloned and Copy
cloned := maps.Clone[map[string]string](m)
maps.Copy[map[string]string](m3, m)
fmt.Printf("Cloned: %+v \n", cloned)
fmt.Printf("Copied: %+v \n", m3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment