Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "strings"
- )
- func main() {
- decorator1(hi)("world")
- println()
- f := decorator2(hello)
- f("world")
- }
- func decorator1(f func(s string) error) func(s string) error {
- return func(s string) error {
- fmt.Println("hello hello hello")
- e := f(s)
- return e
- }
- }
- func decorator2(f func(s string)) func(s string) {
- return func(s string) {
- fmt.Println("hello hello hello")
- f(s)
- }
- }
- func hi(s string) error {
- fmt.Println("hi " + strings.Repeat(s, 3))
- return nil
- }
- func hello(s string) {
- fmt.Println("hi " + strings.Repeat(s, 3))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement