Skip to content

Instantly share code, notes, and snippets.

@mrsimonemms
Created December 25, 2022 17:18
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 mrsimonemms/2586f540dcb816fd086cc955818130fd to your computer and use it in GitHub Desktop.
Save mrsimonemms/2586f540dcb816fd086cc955818130fd to your computer and use it in GitHub Desktop.
Golang Is function
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