Standard library / go/types
go/types.Union
Represents a union of type terms, used as an interface constraint element. Expected stdout: '2\n'.
Formal Syntax & Structure
go syntaxgo
type Union struct {}Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func union() *types.Union { return types.NewUnion([]*types.Term{term(), types.NewTerm(false, types.Typ[types.String])})}
func term() *types.Term { return types.NewTerm(true, types.Typ[types.Int]) }
func main() { fmt.Println(union().Len()) }