Re: [go-nuts] Whats wrong with my builder pattern

2021-12-05 Thread Tyler Compton
It's because your method receivers are values, not pointers: func (b Builder) setFirst() { b.firstElement = "First element" } In Go, method receivers work a lot like regular function arguments. When you call the above method, you're operating on a copy of the Builder struct. Any time you pass

Re: [go-nuts] Whats wrong with my builder pattern

2021-12-05 Thread Reto
Hi, https://go.dev/doc/faq#methods_on_values_or_pointers >First, and most important, does the method need to modify the receiver? If it >does, the receiver must be a pointer. (Slices and maps act as references, so >their story is a little more subtle, but for instance to change the length of >