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 >

[go-nuts] Whats wrong with my builder pattern

2021-12-05 Thread Денис Мухортов
I have 2 empty strings in the output. But why? https://play.golang.com/p/v7zEVBM17YH -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googl