Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "strings"
  6. )
  7.  
  8. func main() {
  9. decorator1(hi)("world")
  10. println()
  11.  
  12. f := decorator2(hello)
  13. f("world")
  14. }
  15.  
  16. func decorator1(f func(s string) error) func(s string) error {
  17. return func(s string) error {
  18. fmt.Println("hello hello hello")
  19. e := f(s)
  20. return e
  21. }
  22. }
  23.  
  24. func decorator2(f func(s string)) func(s string) {
  25. return func(s string) {
  26. fmt.Println("hello hello hello")
  27. f(s)
  28. }
  29. }
  30.  
  31. func hi(s string) error {
  32. fmt.Println("hi " + strings.Repeat(s, 3))
  33. return nil
  34. }
  35.  
  36. func hello(s string) {
  37. fmt.Println("hi " + strings.Repeat(s, 3))
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement