Standard library / go/types
go/types.Satisfies()
Reports whether a type satisfies a type constraint. Expected stdout: 'true false\n'.
Formal Syntax & Structure
go syntaxgo
func Satisfies(V Type, T *Interface) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| V | Type | Source or candidate type. |
| T | *Interface | Destination type or interface, or type to inspect. |
Return Value
bool
Reports whether a type satisfies a type constraint.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { u := types.NewUnion([]*types.Term{types.NewTerm(true, types.Typ[types.Int])}) c := types.NewInterfaceType(nil, []types.Type{u}).Complete() fmt.Println(types.Satisfies(types.Typ[types.Int], c), types.Satisfies(types.Typ[types.String], c))}