Maps EqualFunc Value Comparison
Compare two maps with maps.EqualFunc and delegate value comparison to slices.Equal, so nested slices match element-wise instead of by identity.
Code
package main
import (
"fmt"
"maps"
"slices"
)
func main() {
left := map[string][]int{"a": {1, 2}, "b": {3}}
right := map[string][]int{"a": {1, 2}, "b": {3}}
// slice values are not comparable, so EqualFunc takes the comparison
same := maps.EqualFunc(left, right, func(x, y []int) bool {
return slices.Equal(x, y)
})
fmt.Println("equal values:", same)
right["b"] = []int{3, 4}
fmt.Println("after edit:", maps.EqualFunc(left, right, slices.Equal))
fmt.Println("key count:", len(left), len(right))
// different key sets short-circuit before the callback runs
extra := map[string][]int{"a": {1, 2}, "b": {3}, "c": nil}
fmt.Println("extra key:", maps.EqualFunc(left, extra, slices.Equal))
}The sequence at runtime
Maps EqualFunc Value Comparison is built around the function main.
Points of care
- No package manager involved — every call resolves to a built-in API.
Putting it to use
Signature: func main()
The run emits 3 labeled sections — equal values:, after edit:, key count: — one per step.
Core lines
return slices.Equal(x, y)
Interactive Tools for This Topic
cURL to Python & Go ConverterTranslate curl CLI commands with headers, auth, JSON bodies, and timeouts into ready-to-run Python requests and Go net/http client code snippets.JSON Diff ViewerCompare two JSON documents and list every added, removed, and changed path in a structural diff, with clear before and after values.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does Maps EqualFunc Value Comparison print when run?
- No setup needed: run the file and look for labeled lines like `equal values:`, `after edit:`, `key count:` in the output.
Report a problem with this exampleOpens a pre-filled issue on GitHub.