Skip to content

Instantly share code, notes, and snippets.

@iamgoangle
Created May 27, 2020 16:11
Show Gist options
  • Save iamgoangle/b29709cce3497c61126eeb0d76c0bce7 to your computer and use it in GitHub Desktop.
Save iamgoangle/b29709cce3497c61126eeb0d76c0bce7 to your computer and use it in GitHub Desktop.
Golang Higher-Order-Function
package main
import (
"fmt"
)
type opt struct {
name string
}
type HelloOption func(o *opt)
func main() {
o := &opt{
name: "golf",
}
override := Hello("Hello, playground")
override(o)
fmt.Println(o)
}
func Hello(name string) HelloOption {
return func(o *opt) {
o.name = name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment