github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/method36.gno (about) 1 package main 2 3 import "fmt" 4 5 type Foo struct { 6 A int 7 } 8 9 func (f Foo) WithValue(x int) *Foo { 10 f.A = x 11 return &f 12 } 13 14 func main() { 15 f1 := Foo{A: 1} 16 fmt.Println(f1.WithValue(2)) 17 fmt.Println(f1) 18 } 19 20 // Output: 21 // &{2} 22 // {1}