Standard library / go/types

go/types.Union.Len()

Returns the number of union terms. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func (u *Union) Len() int

Return Value

int

Returns the number of union terms.

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() { v := union(); fmt.Println(v.Len()) }
Go Reference