Skip to content

Instantly share code, notes, and snippets.

@mrsimonemms
Created December 25, 2022 17:18
Show Gist options
  • 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