Created
October 23, 2020 23:10
-
-
Save namp10010/5694edad5b2fd664185a82587b524b62 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" | |
func main() { | |
var sendEmail emailAction = func(payload string) { | |
fmt.Printf("sending email: %v\n", payload) | |
} | |
action := sendEmail. | |
authenticate("username:password"). | |
connectToServer("email-server:443") | |
action("my email") | |
} | |
type emailAction func(payload string) | |
func (a emailAction) connectToServer(server string) emailAction { | |
return func(payload string) { | |
fmt.Printf("connecting to server: %v\n", server) | |
a(payload) | |
} | |
} | |
func (a emailAction) authenticate(cred string) emailAction { | |
return func(payload string) { | |
fmt.Printf("authenticating with cred: %v\n", cred) | |
a(payload) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment