must added
This commit is contained in:
		
							
								
								
									
										37
									
								
								must.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								must.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
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
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user