From 4833c8bb7459976009a908b27528db0af7c0ecb4 Mon Sep 17 00:00:00 2001 From: YikesHome <31678324+yikeshome@users.noreply.github.com> Date: Thu, 31 Oct 2019 03:31:07 +0800 Subject: [PATCH] Create decorate.go --- structural/decorate.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 structural/decorate.go diff --git a/structural/decorate.go b/structural/decorate.go new file mode 100644 index 0000000..4dccbe6 --- /dev/null +++ b/structural/decorate.go @@ -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