Created
May 27, 2020 16:11
-
-
Save iamgoangle/b29709cce3497c61126eeb0d76c0bce7 to your computer and use it in GitHub Desktop.
Golang Higher-Order-Function
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" | |
| ) | |
| 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