assume

package
v0.0.0-...-4ce39b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package assume provides assertions that panic on violation.

This serves two purposes:

  1. Failing fast.
  2. 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T comparable](x, y T)

Equal panics if the items are not equal.

func Equalf

func Equalf[T comparable](x, y T, format string, args ...any)

Equalf panics if the items are not equal.

func NotNilMap

func NotNilMap[K comparable, V any](m map[K]V)

NotNilMap panics if the map is nil.

func NotNilMapf

func NotNilMapf[K comparable, V any](m map[K]V, format string, args ...any)

NotNilMapf panics if the map is nil.

func NotNilSlice

func NotNilSlice[V any](s []V)

NotNilSlice panics if the slice is nil.

func NotNilSlicef

func NotNilSlicef[V any](s []V, format string, args ...any)

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.

func Success

func Success(err error)

Success panics if the provided error is not nil.

func Successf

func Successf(err error, format string, args ...any)

Successf panics if the provided error is not nil.

func True

func True(ok bool)

True panics if the condition is false.

func Truef

func Truef(ok bool, format string, args ...any)

Truef panics if the condition is false.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL