-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmustwith5.go
44 lines (38 loc) · 890 Bytes
/
mustwith5.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
package yeh
import "fmt"
func MustWith5[T1, T2, T3, T4, T5 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, err error) mustWith5[T1, T2, T3, T4, T5] {
return mustWith5[T1, T2, T3, T4, T5]{
t1: t1,
t2: t2,
t3: t3,
t4: t4,
t5: t5,
err: err,
}
}
type mustWith5[T1, T2, T3, T4, T5 any] struct {
t1 T1
t2 T2
t3 T3
t4 T4
t5 T5
err error
}
func (m mustWith5[T1, T2, T3, T4, T5]) Replace(err error) (T1, T2, T3, T4, T5) {
if m.err != nil {
panic(err)
}
return m.t1, m.t2, m.t3, m.t4, m.t5
}
func (m mustWith5[T1, T2, T3, T4, T5]) Wrap(err error) (T1, T2, T3, T4, T5) {
if m.err != nil {
panic(fmt.Errorf("%s: [%w]", m.err.Error(), err))
}
return m.t1, m.t2, m.t3, m.t4, m.t5
}
func (m mustWith5[T1, T2, T3, T4, T5]) Callback(fn FnErrorCallback) (T1, T2, T3, T4, T5) {
if cerr := fn(m.err); cerr != nil {
panic(cerr)
}
return m.t1, m.t2, m.t3, m.t4, m.t5
}