Skip to content

Instantly share code, notes, and snippets.

@thekostya
Last active March 6, 2018 13:54
Show Gist options
  • Save thekostya/55c793852afc0c80491bfc5fd175be8f to your computer and use it in GitHub Desktop.
Save thekostya/55c793852afc0c80491bfc5fd175be8f to your computer and use it in GitHub Desktop.
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