Documentation ¶
Overview ¶
Package assume provides assertions that panic on violation.
This serves two purposes:
- Failing fast.
- Remove unnecessary branches and the temptation to test them.
Nil ¶
Detecting nil is a bit of a mess in Go because of nil interfaces. We have decided to avoid generic predicates such as NotNil in favour of the much less error-prone NotZero, NotNilSlice, NotNilMap, etc. These functions use generics to convey the narrow type instead of any, which is essential to avoid some important pitfalls.
Index ¶
- func Equal[T comparable](x, y T)
- func Equalf[T comparable](x, y T, format string, args ...any)
- func NotNilMap[K comparable, V any](m map[K]V)
- func NotNilMapf[K comparable, V any](m map[K]V, format string, args ...any)
- func NotNilSlice[V any](s []V)
- func NotNilSlicef[V any](s []V, format string, args ...any)
- func NotZero[V comparable](v V)
- func NotZerof[V comparable](v V, format string, args ...any)
- func Success(err error)
- func Successf(err error, format string, args ...any)
- func True(ok bool)
- func Truef(ok bool, format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equalf ¶
func Equalf[T comparable](x, y T, format string, args ...any)
Equalf panics if the items are not equal.
func NotNilMapf ¶
func NotNilMapf[K comparable, V any](m map[K]V, format string, args ...any)
NotNilMapf panics if the map is nil.
func NotNilSlicef ¶
NotNilSlicef panics if the slice is nil.
func NotZero ¶
func NotZero[V comparable](v V)
NotZero panics if the value is zero. Only applicable to comparable types.
This function can be used to check comparable types against nil.
func NotZerof ¶
func NotZerof[V comparable](v V, format string, args ...any)
NotZerof panics if the value is zero. Only applicable to comparable types.
Types ¶
This section is empty.