Skip to content

Instantly share code, notes, and snippets.

@bbasata
Last active July 5, 2025 19:26
Show Gist options
  • Select an option

  • Save bbasata/238aa494e15993a4ecf75f6d564b954a to your computer and use it in GitHub Desktop.

Select an option

Save bbasata/238aa494e15993a4ecf75f6d564b954a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"example.org/int/typ"
)
func main() {
for item := range items {
if item.StringValue() != nil {
fmt.Println("Found a string value:", *item.StringValue())
}
}
}
func items(push func(typ.Variant) bool) {
push(typ.Int32(1))
push(typ.String("hat"))
push(typ.String("bat"))
push(typ.Int32(3000))
}
package typ
type Variant interface {
StringValue() *string
Int32Value() *int32
}
type variant struct {
stringValue *string
int32Value *int32
}
func String(value string) Variant {
return variant{stringValue: &value}
}
func Int32(value int32) Variant {
return variant{int32Value: &value}
}
func (t variant) StringValue() *string {
return t.stringValue
}
func (t variant) Int32Value() *int32 {
return t.int32Value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment