40 lines
643 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"
)
type item interface {
discount(ratio float64)
2019-09-02 22:33:34 +03:00
fmt.Stringer
}
type list []item
func (l list) String() string {
if len(l) == 0 {
return "Sorry. We're waiting for delivery 🚚."
}
var str strings.Builder
for _, it := range l {
str.WriteString(it.String())
str.WriteRune('\n')
}
return str.String()
}
func (l list) discount(ratio float64) {
for _, it := range l {
it.discount(ratio)
}
}