refactor: stringer

This commit is contained in:
Inanc Gumus
2019-10-17 20:23:45 +03:00
parent c062a46355
commit 47b24c7649
8 changed files with 41 additions and 19 deletions

View File

@@ -10,17 +10,14 @@ package main
import "fmt"
func main() {
// The money type is a stringer.
// You don't need to call the String method when printing a value of it.
// var pocket money = 10
// fmt.Println(pocket)
l := list{
{title: "moby dick", price: 10, released: toTimestamp(118281600)},
{title: "odyssey", price: 15, released: toTimestamp("733622400")},
{title: "hobbit", price: 25},
}
l.discount(.5)
// The list is a stringer.
// The `fmt.Print` function can print the `l`
// by calling `l`'s `String()` method.
@@ -29,4 +26,9 @@ func main() {
// detect whether a type is a Stringer:
// https://golang.org/src/fmt/print.go#L627
fmt.Print(l)
// The money type is a stringer.
// You don't need to call the String method when printing a value of it.
// var pocket money = 10
// fmt.Println("I have", pocket)
}