30 lines
462 B
Go
Raw Normal View History

2019-10-31 03:31:07 +08:00
package main
2020-05-08 17:07:20 +08:00
import "log"
2019-10-31 03:31:07 +08:00
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)
2020-05-08 17:07:20 +08:00
return result
2019-10-31 03:31:07 +08:00
}
}
func Double(n int) int {
2020-05-08 17:07:20 +08:00
return n * 2
2019-10-31 03:31:07 +08:00
}
2020-05-08 17:07:20 +08:00
func main() {
f := LogDecorate(Double)
f(5)
2019-10-31 03:31:07 +08:00
}
// Starting execution with the integer 5
// Execution is completed with the result 10