Skip to content

Instantly share code, notes, and snippets.

@SeongJuMoon
Created December 29, 2019 14:15
Show Gist options
  • Select an option

  • Save SeongJuMoon/977c310c4b2465693d0344c3a7659ac1 to your computer and use it in GitHub Desktop.

Select an option

Save SeongJuMoon/977c310c4b2465693d0344c3a7659ac1 to your computer and use it in GitHub Desktop.
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