Last active
March 6, 2018 13:54
-
-
Save thekostya/55c793852afc0c80491bfc5fd175be8f 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" | |
) | |
type Printer func (s string) | |
type PrinterDecorator func (Printer) Printer | |
func DecoratorWithStartEnd(startStr, endStr string) PrinterDecorator { | |
return func (p Printer) Printer { | |
return func (s string) { | |
fmt.Println(startStr) | |
p(s) | |
fmt.Println(endStr) | |
} | |
} | |
} | |
func doSomething(s string) { | |
fmt.Println(s) | |
} | |
func main() { | |
decorator1 := DecoratorWithStartEnd("Before 1", "After 1") | |
decorator1(doSomething)("Do something") | |
decorator2 := DecoratorWithStartEnd("Before 2", "After 2") | |
decorator2(doSomething)("Do something") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment