Create decorate.go

This commit is contained in:
YikesHome 2019-10-31 03:31:07 +08:00 committed by GitHub
parent e2de2e1600
commit 4833c8bb74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

28
structural/decorate.go Normal file
View 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