Created
March 9, 2023 11:06
-
-
Save fbiville/88ee2d485b6736c9a29adc252e97feb9 to your computer and use it in GitHub Desktop.
DeepEqual and functions
This file contains hidden or 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" | |
"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() | |
} |
This file contains hidden or 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
=== 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