34 lines
562 B
Go
Raw Normal View History

2019-09-02 22:33:34 +03:00
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"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 {
fmt.Fprintf(&str, "* %s\n", p)
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
}
}