Last active
March 8, 2023 21:26
-
-
Save iancharters/28e1b6bac4bdfa2d76b5b74743718f33 to your computer and use it in GitHub Desktop.
This file contains 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" | |
) | |
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