Standard library / go/types

go/types.Union.String()

Formats the union as a list of terms separated by vertical bars. Expected stdout: '~int | string\n'.

Formal Syntax & Structure

go syntaxgo
func (u *Union) String() string

Return Value

string

Formats the union as a list of terms separated by vertical bars.

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.String()) }
Go Reference