37 lines
742 B
Go
Raw Permalink Normal View History

2019-09-02 22:33:34 +03:00
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
2019-10-30 19:34:44 +03:00
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
2019-09-02 22:33:34 +03:00
package main
import (
"strings"
)
2019-10-17 14:11:51 +03:00
type list []*product
2019-09-02 22:33:34 +03:00
func (l list) String() string {
if len(l) == 0 {
2019-10-17 14:11:51 +03:00
return "Sorry. We're waiting for delivery 🚚.\n"
2019-09-02 22:33:34 +03:00
}
var str strings.Builder
2019-10-17 14:11:51 +03:00
for _, p := range l {
2019-10-17 20:23:45 +03:00
// fmt.Printf("* %s\n", p)
str.WriteString("* ")
str.WriteString(p.String())
str.WriteRune('\n')
2019-09-02 22:33:34 +03:00
}
return str.String()
}
func (l list) discount(ratio float64) {
2019-10-17 14:11:51 +03:00
for _, p := range l {
p.discount(ratio)
2019-09-02 22:33:34 +03:00
}
}