Standard library / maps

maps.EqualFunc()

Compares key sets and corresponding values using a caller-defined equality function; value types may differ. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool

Parameters & Attributes

NameTypeDescription
m1M1First map to compare.
m2M2Second map to compare.
eqfunc(V1, V2) boolEquality callback, true for equivalent elements.

Return Value

bool

Compares key sets and corresponding values using a caller-defined equality function; value types may differ.

Working Example

Example Snippetgo
package main
import (  "fmt"  "maps")
func main() {  fmt.Println(maps.EqualFunc(map[string]string{"a": "xx"}, map[string]int{"a": 2}, func(s string, n int) bool { return len(s) == n }))}
Go Reference