Values & References15 / 15
Up next

Value receiver gets a copy

package main

import "fmt"

type Counter struct{ n int }

// value receiver: operates on a copy
func (c Counter) Inc() {
	c.n++
}

func main() {
	c := Counter{}
	c.Inc()
	fmt.Println(c.n) // 0, unchanged
}
What you're solving

it cannot mutate the original