Skip to content

Commit 4833c8b

Browse files
authored
Create decorate.go
1 parent e2de2e1 commit 4833c8b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

structural/decorate.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
type Object func(int) int
4+
5+
func LogDecorate(fn Object) Object {
6+
return func(n int) int {
7+
log.Println("Starting the execution with the integer", n)
8+
9+
result := fn(n)
10+
11+
log.Println("Execution is completed with the result", result)
12+
13+
return result
14+
}
15+
}
16+
17+
func Double(n int) int {
18+
return n * 2
19+
}
20+
21+
func main(){
22+
f := LogDecorate(Double)
23+
f(5)
24+
}
25+
26+
27+
// Starting execution with the integer 5
28+
// Execution is completed with the result 10

0 commit comments

Comments
 (0)