mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-21 20:36:01 +03:00
Create decorate.go
This commit is contained in:
parent
e2de2e1600
commit
4833c8bb74
28
structural/decorate.go
Normal file
28
structural/decorate.go
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
type Object func(int) int
|
||||
|
||||
func LogDecorate(fn Object) Object {
|
||||
return func(n int) int {
|
||||
log.Println("Starting the execution with the integer", n)
|
||||
|
||||
result := fn(n)
|
||||
|
||||
log.Println("Execution is completed with the result", result)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func Double(n int) int {
|
||||
return n * 2
|
||||
}
|
||||
|
||||
func main(){
|
||||
f := LogDecorate(Double)
|
||||
f(5)
|
||||
}
|
||||
|
||||
|
||||
// Starting execution with the integer 5
|
||||
// Execution is completed with the result 10
|
Loading…
Reference in New Issue
Block a user