38 lines
719 B
Go
38 lines
719 B
Go
package adverr
|
|
|
|
// Must panics if err is not nil.
|
|
// It returns value otherwise
|
|
func Must[T any](value T, err error) T {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return value
|
|
}
|
|
|
|
// Must2 panics if err is not nil.
|
|
// It returns a and b otherwise
|
|
func Must2[A, B any](a A, b B, err error) (A, B) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return a, b
|
|
}
|
|
|
|
// Must3 panics if err is not nil.
|
|
// It returns a, b and c otherwise
|
|
func Must3[A, B, C any](a A, b B, c C, err error) (A, B, C) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return a, b, c
|
|
}
|
|
|
|
// Must4 panics if err is not nil.
|
|
// It returns a, b and c otherwise
|
|
func Must4[A, B, C, D any](a A, b B, c C, d D, err error) (A, B, C, D) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return a, b, c, d
|
|
}
|