Skip to content

Instantly share code, notes, and snippets.

@iancharters
Last active March 8, 2023 21:26
Show Gist options
  • Save iancharters/28e1b6bac4bdfa2d76b5b74743718f33 to your computer and use it in GitHub Desktop.
Save iancharters/28e1b6bac4bdfa2d76b5b74743718f33 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type thing struct {
val string
}
type Option interface {
apply(*thing)
}
type optionFn func(*thing)
func (fn optionFn) apply(t *thing) { fn(t) }
func newOpt(s string) Option {
return optionFn(func(t *thing) {
t.val = s
})
}
func main() {
t := &thing{"old"}
fmt.Println(t)
fn := newOpt("new")
fn.apply(t)
fmt.Println(t)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment