Skip to content

Instantly share code, notes, and snippets.

@bbasata
Created July 5, 2025 23:26
Show Gist options
  • Select an option

  • Save bbasata/2524a3274dbf68d5c2400e4a4b727532 to your computer and use it in GitHub Desktop.

Select an option

Save bbasata/2524a3274dbf68d5c2400e4a4b727532 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())
if *item.StringValue() == "bat" {
break
}
}
}
}
func items(push func(typ.Variant) bool) {
for item := range integers {
formattedItem := typ.String(string(item))
if !push(formattedItem) {
return
}
}
for item := range words {
formattedItem := typ.String(item)
if !push(formattedItem) {
return
}
}
}
func integers(push func(int32) bool) {
if !push(1) ||
!push(2) ||
!push(3_000) ||
!push(4) ||
!push(5) {
return
}
}
func words(push func(string) bool) {
if !push("hat") ||
!push("bat") ||
!push("cat") ||
!push("mat") {
return
}
}
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