Standard library / go/types
go/types.NewUnion()
Constructs a nonempty union of type terms for use in constraints. Expected stdout: '~int | string\n'.
Formal Syntax & Structure
go syntaxgo
func NewUnion(terms []*Term) *UnionParameters & Attributes
| Name | Type | Description |
|---|---|---|
| terms | []*Term | Input to the operation as described above. |
Return Value
*Union
Constructs a nonempty union of type terms for use in constraints.
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()) }