Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950package types
import "strings"
// Union is a sum type where any of the specified types can be the real type.type Union struct { Types []Type}
// Index returns the position of the given type within the union.func (u *Union) Index(search Type) int { for i, typ := range u.Types { if Is(search, typ) { return i } }
return -1}
// Name returns the type name.func (u *Union) Name() string { b := strings.Builder{}
for i, typ := range u.Types { b.WriteString(typ.Name())
if i != len(u.Types)-1 { b.WriteString(" | ") } }
return b.String()}
// Size returns the total size in bytes.func (u *Union) Size() int { size := 0
for _, typ := range u.Types { size = max(size, typ.Size()) }
return size}
// String returns the type name.func (u *Union) String() string { return u.Name()}