Created
December 25, 2022 17:18
-
-
Save mrsimonemms/2586f540dcb816fd086cc955818130fd to your computer and use it in GitHub Desktop.
Golang Is function
This file contains 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" | |
"go/types" | |
) | |
func Is[T types.Type](v types.Type) bool { | |
_, ok := v.(T) | |
return ok | |
} | |
func main() { | |
fmt.Println(Is[*types.Array](&types.Array{})) | |
fmt.Println(Is[*types.Interface](&types.Array{})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment