Documentation ¶
Overview ¶
builtin contains additional utility functions for built-in types of the Go programming languages. This package contains the utils that apply to types and functions that are always immediately available.
TODO consider adding function for "compacting" a map, i.e. copying content over into new map such that there is no memory wasted after intense use. TODO consider if we need to move slices and maps utils out to prevent `builtin` from growing too big.
Index ¶
- func Add[T types.Number](a, b T) T
- func EqualT[T Equaler[T]](a, b T) bool
- func EqualsAny[T comparable](value T, matches ...T) bool
- func EqualsAnyOf[T comparable](matches ...T) func(v T) bool
- func EqualsFixedOf[T comparable](fixed T) func(T) bool
- func Error[T any](result T, err error) error
- func Error2[T, T2 any](result T, result2 T2, err error) error
- func Error3[T, T2, T3 any](result T, result2 T2, result3 T3, err error) error
- func Error4[T, T2, T3, T4 any](result T, result2 T2, result3 T3, result4 T4, err error) error
- func Expect[T any](result T, err error) T
- func Expect2[T any, T2 any](result T, result2 T2, err error) (T, T2)
- func Expect3[T, T2, T3 any](result T, result2 T2, result3 T3, err error) (T, T2, T3)
- func Expect4[T, T2, T3, T4 any](result T, result2 T2, result3 T3, result4 T4, err error) (T, T2, T3, T4)
- func Multiply[T types.Number](a, b T) T
- func NonZero[T types.Number](v T) bool
- func Ok[T any](result T, ok bool) T
- func Ok2[T any, T2 any](result T, result2 T2, ok bool) (T, T2)
- func Ok3[T any, T2 any, T3 any](result T, result2 T2, result3 T3, ok bool) (T, T2, T3)
- func Ok4[T any, T2 any, T3 any, T4 any](result T, result2 T2, result3 T3, result4 T4, ok bool) (T, T2, T3, T4)
- func RecoverLogged(format string)
- func RecoverLoggedExit(code int, format string)
- func RecoverLoggedStackTrace(format string)
- func RecoverLoggedStackTraceExit(code int, format string)
- func Zero[T types.Number](v T) bool
- type Equaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add is a trivial func. It does not protect its boundaries, e.g. overflowing. It can be referenced, for example in `Reduce`.
func EqualsAny ¶
func EqualsAny[T comparable](value T, matches ...T) bool
EqualsAny matches the specified value with any of the provided `matches` values. It returns `true` if it is any of the provided matches, or `false` if none match.
func EqualsAnyOf ¶
func EqualsAnyOf[T comparable](matches ...T) func(v T) bool
EqualsAnyOf creates a closure that tests any provided value against a list of matches.
func EqualsFixedOf ¶
func EqualsFixedOf[T comparable](fixed T) func(T) bool
EqualsFixedOf creates a closure that tests any provided value against a fixed value.
func Expect ¶
Expect checks for error and either panics on error, or passes through only the result.
func Expect2 ¶
Expect2 checks for error and either panics on error, or passes through only the results.
func Expect3 ¶
Expect3 checks for error and either panics on error, or passes through only the results.
func Expect4 ¶
func Expect4[T, T2, T3, T4 any](result T, result2 T2, result3 T3, result4 T4, err error) (T, T2, T3, T4)
Expect4 checks for error and either panics on error, or passes through only the results.
func Multiply ¶
Multiply is a trivial func. It does not protect its boundaries, e.g. overflowing. It can be referenced, for example in `Reduce`.
func RecoverLogged ¶
func RecoverLogged(format string)
RecoverLogged recovers from panic and logs the payload. This function must be _deferred_ to be useful.
func RecoverLoggedExit ¶
RecoverLoggedExit recovers from panic and logs the payload, same as RecoverLogged, except that calls `os.Exit(code)` after recovering a non-nil (panic-)value to abnormally terminate the program after logging the unhandled panic. This function must be _deferred_ to be useful.
func RecoverLoggedStackTrace ¶
func RecoverLoggedStackTrace(format string)
RecoverLoggedStackTrace calls `recover()` and in case the goroutine was indeed panicking, it writes the error message and a stack trace to log. This function must be _deferred_ to be useful.
func RecoverLoggedStackTraceExit ¶
RecoverLoggedStackTraceExit calls `recover()` and in case the goroutine was indeed panicking, it writes the error message and a stack trace to log. After logging the panic, exit with specified exit-code. This function must be _deferred_ to be useful.
Types ¶
Directories ¶
Path | Synopsis |
---|---|
bitset is a package that provides a bit-wise set implementation for indexes/positions.
|
bitset is a package that provides a bit-wise set implementation for indexes/positions. |
Multiset is a map with uint-values that represents a set of elements with their respective number of elements.
|
Multiset is a map with uint-values that represents a set of elements with their respective number of elements. |
set is a map of keys with unit-values (`struct{}{}`).
|
set is a map of keys with unit-values (`struct{}{}`). |