Created
December 29, 2019 14:15
-
-
Save SeongJuMoon/977c310c4b2465693d0344c3a7659ac1 to your computer and use it in GitHub Desktop.
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" | |
| "strings" | |
| ) | |
| type StringFunc func(a string) string | |
| func Compose(f StringFunc, g StringFunc) StringFunc { | |
| return func(s string) string { | |
| return g(f(s)) | |
| } | |
| } | |
| func main() { | |
| var recognize = func(name string) string { | |
| return fmt.Sprintf("Hey %s", name) | |
| } | |
| var emphasize = func(statement string) string { | |
| return fmt.Sprintf(strings.ToUpper(statement) + "!") | |
| } | |
| var compressed = Compose(recognize, emphasize) | |
| fmt.Println(compressed("gopher")) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment