// Chapter 26 example: a counter, with a method that gives back a changed copy. // Run with: go run exercises/26/03-counter.go package main import "fmt" type counter struct { count int } func (c counter) show() { fmt.Println("Count:", c.count) } func (c counter) step() counter { c.count = c.count + 1 return c } func main() { c := counter{} c = c.step() c = c.step() c = c.step() c.show() // Count: 3 // Try this: add a method reset that gives back a counter with count set // to 0, assign its result back to c, and call c.show() again. }