Skip to content

Instantly share code, notes, and snippets.

@fbiville
Created March 9, 2023 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbiville/88ee2d485b6736c9a29adc252e97feb9 to your computer and use it in GitHub Desktop.
Save fbiville/88ee2d485b6736c9a29adc252e97feb9 to your computer and use it in GitHub Desktop.
DeepEqual and functions
package main
import (
"fmt"
"reflect"
)
func main() {
foo2 := foo
fmt.Println("=== DeepEqual")
fmt.Println(reflect.DeepEqual(foo, foo))
fmt.Println(reflect.DeepEqual(foo, foo2))
fmt.Println(reflect.DeepEqual(foo, bar))
fmt.Println("=== functionsEqual")
fmt.Println(functionsEqual(foo, foo))
fmt.Println(functionsEqual(foo, foo2))
fmt.Println(functionsEqual(foo, bar))
}
func foo() {
}
func bar() {
}
func functionsEqual(f1, f2 any) bool {
return reflect.ValueOf(f1).Pointer() == reflect.ValueOf(f2).Pointer()
}
=== DeepEqual
false
false
false
=== functionsEqual
true
true
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment