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) bool

Parameters & Attributes

NameTypeDescription
VTypeSource or candidate type.
T*InterfaceDestination 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))}
Go Reference