builtin

package
v0.0.0-...-02e3eee Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: GPL-3.0, LGPL-3.0 Imports: 5 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[T types.Number](a, b T) T

Add is a trivial func. It does not protect its boundaries, e.g. overflowing. It can be referenced, for example in `Reduce`.

func EqualT

func EqualT[T Equaler[T]](a, b T) bool

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 Error

func Error[T any](result T, err error) error

Error drops the result, returning only the error

func Error2

func Error2[T, T2 any](result T, result2 T2, err error) error

Error2 drops two results, returning only the error

func Error3

func Error3[T, T2, T3 any](result T, result2 T2, result3 T3, err error) error

Error3 drops three results, returning only the error

func Error4

func Error4[T, T2, T3, T4 any](result T, result2 T2, result3 T3, result4 T4, err error) error

Error4 drops four results, returning only the error

func Expect

func Expect[T any](result T, err error) T

Expect checks for error and either panics on error, or passes through only the result.

func Expect2

func Expect2[T any, T2 any](result T, result2 T2, err error) (T, T2)

Expect2 checks for error and either panics on error, or passes through only the results.

func Expect3

func Expect3[T, T2, T3 any](result T, result2 T2, result3 T3, err error) (T, T2, T3)

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

func Multiply[T types.Number](a, b T) T

Multiply is a trivial func. It does not protect its boundaries, e.g. overflowing. It can be referenced, for example in `Reduce`.

func NonZero

func NonZero[T types.Number](v T) bool

NonZero tests whether provided value `v` is non-zero.

func Ok

func Ok[T any](result T, ok bool) T

func Ok2

func Ok2[T any, T2 any](result T, result2 T2, ok bool) (T, T2)

func Ok3

func Ok3[T any, T2 any, T3 any](result T, result2 T2, result3 T3, ok bool) (T, T2, T3)

func Ok4

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

func RecoverLogged(format string)

RecoverLogged recovers from panic and logs the payload. This function must be _deferred_ to be useful.

func RecoverLoggedExit

func RecoverLoggedExit(code int, format string)

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

func RecoverLoggedStackTraceExit(code int, format string)

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.

func Zero

func Zero[T types.Number](v T) bool

Zero tests whether provided value `v` is zero.

Types

type Equaler

type Equaler[T any] interface {
	Equal(o T) bool
}

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{}{}`).

Jump to

Keyboard shortcuts

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