github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/ds/fn_err_link.go (about) 1 package ds 2 3 import ( 4 "reflect" 5 6 "github.com/15mga/kiwi/util" 7 ) 8 9 func NewFnErrLink() *FnErrLink { 10 return &FnErrLink{ 11 Link: NewLink[func() *util.Err](), 12 } 13 } 14 15 type FnErrLink struct { 16 *Link[func() *util.Err] 17 } 18 19 func (l *FnErrLink) Invoke() *util.Err { 20 for e := l.head; e != nil; e = e.Next { 21 err := e.Value() 22 if err != nil { 23 return err 24 } 25 } 26 return nil 27 } 28 29 func (l *FnErrLink) Del(fn func() *util.Err) { 30 pointer := reflect.ValueOf(fn).Pointer() 31 _ = l.Link.Del(func(f func() *util.Err) bool { 32 return reflect.ValueOf(f).Pointer() == pointer 33 }) 34 } 35 36 func (l *FnErrLink) Reset() { 37 l.head = nil 38 l.tail = nil 39 } 40 41 func NewFnErrLink1[T any]() *FnErrLink1[T] { 42 return &FnErrLink1[T]{ 43 Link: NewLink[func(T) *util.Err](), 44 } 45 } 46 47 type FnErrLink1[T any] struct { 48 *Link[func(T) *util.Err] 49 } 50 51 func (l *FnErrLink1[T]) Invoke(obj T) *util.Err { 52 for e := l.head; e != nil; e = e.Next { 53 err := e.Value(obj) 54 if err != nil { 55 return err 56 } 57 } 58 return nil 59 } 60 61 func (l *FnErrLink1[T]) Del(fn func(T) *util.Err) { 62 pointer := reflect.ValueOf(fn).Pointer() 63 _ = l.Link.Del(func(f func(T) *util.Err) bool { 64 return reflect.ValueOf(f).Pointer() == pointer 65 }) 66 } 67 68 func (l *FnErrLink1[T]) Reset() { 69 l.head = nil 70 l.tail = nil 71 } 72 73 func NewFnErrLink2[T0, T1 any]() *FnErrLink2[T0, T1] { 74 return &FnErrLink2[T0, T1]{ 75 Link: NewLink[func(T0, T1) *util.Err](), 76 } 77 } 78 79 type FnErrLink2[T0, T1 any] struct { 80 *Link[func(T0, T1) *util.Err] 81 } 82 83 func (l *FnErrLink2[T0, T1]) Invoke(v0 T0, v1 T1) *util.Err { 84 for e := l.head; e != nil; e = e.Next { 85 err := e.Value(v0, v1) 86 if err != nil { 87 return err 88 } 89 } 90 return nil 91 } 92 93 func (l *FnErrLink2[T0, T1]) Del(fn func(T0, T1) *util.Err) { 94 pointer := reflect.ValueOf(fn).Pointer() 95 _ = l.Link.Del(func(f func(T0, T1) *util.Err) bool { 96 return reflect.ValueOf(f).Pointer() == pointer 97 }) 98 } 99 100 func (l *FnErrLink2[T0, T1]) Reset() { 101 l.head = nil 102 l.tail = nil 103 } 104 105 func NewFnErrLink3[T0, T1, T2 any]() *FnErrLink3[T0, T1, T2] { 106 return &FnErrLink3[T0, T1, T2]{ 107 Link: NewLink[func(T0, T1, T2) *util.Err](), 108 } 109 } 110 111 type FnErrLink3[T0, T1, T2 any] struct { 112 *Link[func(T0, T1, T2) *util.Err] 113 } 114 115 func (l *FnErrLink3[T0, T1, T2]) Invoke(v0 T0, v1 T1, v2 T2) *util.Err { 116 for e := l.head; e != nil; e = e.Next { 117 err := e.Value(v0, v1, v2) 118 if err != nil { 119 return err 120 } 121 } 122 return nil 123 } 124 125 func (l *FnErrLink3[T0, T1, T2]) Del(fn func(T0, T1, T2) *util.Err) { 126 pointer := reflect.ValueOf(fn).Pointer() 127 _ = l.Link.Del(func(f func(T0, T1, T2) *util.Err) bool { 128 return reflect.ValueOf(f).Pointer() == pointer 129 }) 130 } 131 132 func (l *FnErrLink3[T0, T1, T2]) Reset() { 133 l.head = nil 134 l.tail = nil 135 } 136 137 func NewFnErrLink4[T0, T1, T2, T3 any]() *FnErrLink4[T0, T1, T2, T3] { 138 return &FnErrLink4[T0, T1, T2, T3]{ 139 Link: NewLink[func(T0, T1, T2, T3) *util.Err](), 140 } 141 } 142 143 type FnErrLink4[T0, T1, T2, T3 any] struct { 144 *Link[func(T0, T1, T2, T3) *util.Err] 145 } 146 147 func (l *FnErrLink4[T0, T1, T2, T3]) Invoke(v0 T0, v1 T1, v2 T2, v3 T3) *util.Err { 148 for e := l.head; e != nil; e = e.Next { 149 err := e.Value(v0, v1, v2, v3) 150 if err != nil { 151 return err 152 } 153 } 154 return nil 155 } 156 157 func (l *FnErrLink4[T0, T1, T2, T3]) Del(fn func(T0, T1, T2, T3) *util.Err) { 158 pointer := reflect.ValueOf(fn).Pointer() 159 _ = l.Link.Del(func(f func(T0, T1, T2, T3) *util.Err) bool { 160 return reflect.ValueOf(f).Pointer() == pointer 161 }) 162 } 163 164 func (l *FnErrLink4[T0, T1, T2, T3]) Reset() { 165 l.head = nil 166 l.tail = nil 167 } 168 169 func NewFnErrLink5[T0, T1, T2, T3, T4 any]() *FnErrLink5[T0, T1, T2, T3, T4] { 170 return &FnErrLink5[T0, T1, T2, T3, T4]{ 171 Link: NewLink[func(T0, T1, T2, T3, T4) *util.Err](), 172 } 173 } 174 175 type FnErrLink5[T0, T1, T2, T3, T4 any] struct { 176 *Link[func(T0, T1, T2, T3, T4) *util.Err] 177 } 178 179 func (l *FnErrLink5[T0, T1, T2, T3, T4]) Invoke(v0 T0, v1 T1, v2 T2, v3 T3, v4 T4) *util.Err { 180 for e := l.head; e != nil; e = e.Next { 181 err := e.Value(v0, v1, v2, v3, v4) 182 if err != nil { 183 return err 184 } 185 } 186 return nil 187 } 188 189 func (l *FnErrLink5[T0, T1, T2, T3, T4]) Del(fn func(T0, T1, T2, T3, T4) *util.Err) { 190 pointer := reflect.ValueOf(fn).Pointer() 191 _ = l.Link.Del(func(f func(T0, T1, T2, T3, T4) *util.Err) bool { 192 return reflect.ValueOf(f).Pointer() == pointer 193 }) 194 } 195 196 func (l *FnErrLink5[T0, T1, T2, T3, T4]) Reset() { 197 l.head = nil 198 l.tail = nil 199 } 200 201 func NewFnErrLink6[T0, T1, T2, T3, T4, T5 any]() *FnErrLink6[T0, T1, T2, T3, T4, T5] { 202 return &FnErrLink6[T0, T1, T2, T3, T4, T5]{ 203 Link: NewLink[func(T0, T1, T2, T3, T4, T5) *util.Err](), 204 } 205 } 206 207 type FnErrLink6[T0, T1, T2, T3, T4, T5 any] struct { 208 *Link[func(T0, T1, T2, T3, T4, T5) *util.Err] 209 } 210 211 func (l *FnErrLink6[T0, T1, T2, T3, T4, T5]) Invoke(v0 T0, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5) *util.Err { 212 for e := l.head; e != nil; e = e.Next { 213 err := e.Value(v0, v1, v2, v3, v4, v5) 214 if err != nil { 215 return err 216 } 217 } 218 return nil 219 } 220 221 func (l *FnErrLink6[T0, T1, T2, T3, T4, T5]) Del(fn func(T0, T1, T2, T3, T4, T5) *util.Err) { 222 pointer := reflect.ValueOf(fn).Pointer() 223 _ = l.Link.Del(func(f func(T0, T1, T2, T3, T4, T5) *util.Err) bool { 224 return reflect.ValueOf(f).Pointer() == pointer 225 }) 226 } 227 228 func (l *FnErrLink6[T0, T1, T2, T3, T4, T5]) Reset() { 229 l.head = nil 230 l.tail = nil 231 }