Browse Source

util/must: add Get2 for functions that return two values

Updates #cleanup

Signed-off-by: James Sanderson <[email protected]>
James Sanderson 8 months ago
parent
commit
735f15cb49
1 changed files with 8 additions and 0 deletions
  1. 8 0
      util/must/must.go

+ 8 - 0
util/must/must.go

@@ -23,3 +23,11 @@ func Get[T any](v T, err error) T {
 	}
 	return v
 }
+
+// Get2 returns v1 and v2 as is. It panics if err is non-nil.
+func Get2[T any, U any](v1 T, v2 U, err error) (T, U) {
+	if err != nil {
+		panic(err)
+	}
+	return v1, v2
+}