Last active
July 5, 2025 19:26
-
-
Save bbasata/238aa494e15993a4ecf75f6d564b954a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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