/
gen_strings_immutableGen.go
125 lines (100 loc) · 1.8 KB
/
gen_strings_immutableGen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Code generated by immutableGen. DO NOT EDIT.
package example
//immutableVet:skipFile
import (
"myitcv.io/immutable"
)
// via go generate, this template is code generated into the immutable Person
// struct within the same package
//
// Person is an immutable type and has the following template:
//
// struct {
// Name string
// Age int
// }
//
type Person struct {
field_Name string
field_Age int
mutable bool
__tmpl *_Imm_Person
}
var _ immutable.Immutable = new(Person)
var _ = new(Person).__tmpl
func (s *Person) AsMutable() *Person {
if s.Mutable() {
return s
}
res := *s
res.mutable = true
return &res
}
func (s *Person) AsImmutable(v *Person) *Person {
if s == nil {
return nil
}
if s == v {
return s
}
s.mutable = false
return s
}
func (s *Person) Mutable() bool {
return s.mutable
}
func (s *Person) WithMutable(f func(si *Person)) *Person {
res := s.AsMutable()
f(res)
res = res.AsImmutable(s)
return res
}
func (s *Person) WithImmutable(f func(si *Person)) *Person {
prev := s.mutable
s.mutable = false
f(s)
s.mutable = prev
return s
}
func (s *Person) IsDeeplyNonMutable(seen map[interface{}]bool) bool {
if s == nil {
return true
}
if s.Mutable() {
return false
}
if seen == nil {
return s.IsDeeplyNonMutable(make(map[interface{}]bool))
}
if seen[s] {
return true
}
seen[s] = true
return true
}
func (s *Person) Age() int {
return s.field_Age
}
// SetAge is the setter for Age()
func (s *Person) SetAge(n int) *Person {
if s.mutable {
s.field_Age = n
return s
}
res := *s
res.field_Age = n
return &res
}
func (s *Person) Name() string {
return s.field_Name
}
// SetName is the setter for Name()
func (s *Person) SetName(n string) *Person {
if s.mutable {
s.field_Name = n
return s
}
res := *s
res.field_Name = n
return &res
}