From e1fb0a4a7483f9037a4623e0a3a7174c9464ce51 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 2 Sep 2019 19:07:24 +0300 Subject: [PATCH] update: little fixes to composition --- interfaces/composition/list.go | 2 +- interfaces/composition/main.go | 44 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/interfaces/composition/list.go b/interfaces/composition/list.go index 2229250..a89abc8 100644 --- a/interfaces/composition/list.go +++ b/interfaces/composition/list.go @@ -29,7 +29,7 @@ func (l list) String() string { for _, it := range l { fmt.Fprintf(&str, "%s\n", it) } - fmt.Fprintf(&str, "\tTOTAL : $%.2f", l.sum()) + fmt.Fprintf(&str, "\tTOTAL : $%.2f\n", l.sum()) return str.String() } diff --git a/interfaces/composition/main.go b/interfaces/composition/main.go index df022e2..49b6996 100644 --- a/interfaces/composition/main.go +++ b/interfaces/composition/main.go @@ -10,7 +10,6 @@ package main import ( "encoding/json" "fmt" - "sort" ) func main() { @@ -24,34 +23,35 @@ func main() { &toy{product{"yoda", 150}}, } - out, _ := json.Marshal(store) + out, _ := json.MarshalIndent(store, "", "\t") fmt.Println(string(out)) - var ( - nilItem item - nilBook *book - ) + // store.discount(.5) + // fmt.Print(store) - fmt.Println("nilBook ?", nilBook == nil) - fmt.Println("nilItem?", nilItem == nil) + // var ( + // nilItem item + // nilBook *book + // ) - nilItem = nilBook - fmt.Println("nilItem?", nilItem == nil) + // fmt.Println("nilBook ?", nilBook == nil) + // fmt.Println("nilItem?", nilItem == nil) - books := store[:3] + // nilItem = nilBook + // fmt.Println("nilItem?", nilItem == nil) - books.discount(.5) - fmt.Printf("%s\n", store) + // books := store[:3] - others := store[3:] - sort.Sort(byPrice(others)) - fmt.Printf("\n%s\n", store) + // books.discount(.5) + // fmt.Printf("%s\n", store) - store = list{books, others} - fmt.Printf("\n%s\n", store) + // others := store[3:] + // sort.Sort(byPrice(others)) + // fmt.Printf("\n%s\n", store) - store.discount(.5) - // sort.Sort(sort.Reverse(byPrice(store))) - sort.Sort(byName(store)) - fmt.Println(store) + // store = list{books, others} + // fmt.Printf("\n%s\n", store) + + // // sort.Sort(sort.Reverse(byPrice(store))) + // sort.Sort(byName(store)) }