utils

package module
v0.0.2024070250 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 32

README

go-utils

Go utils for internal use

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assert = A
View Source
var WaitForDebugger = Debugger

Functions

func A added in v0.0.2024062901

func A(b bool, msgS ...string)

A panics with the given message if the condition is false.

func Bind

func Bind[T any](err error, fn func() (T, error)) (T, error)

Bind returns the result of the given function that can fail if err is nil, otherwise the error.

func Bind0

func Bind0(err error, fn func() error) error

Bind0 is an alias of Then.

func Bind1

func Bind1[T any](err error, fn func() (T, error)) (T, error)

Bind1 is an alias of Bind.

func Bind2

func Bind2[T any, U any](err error, fn func() (T, U, error)) (T, U, error)

func Catch added in v0.0.2024021245

func Catch(errRef *error)

func Debugger added in v0.0.2024021544

func Debugger()

Debugger waits for a debugger to connect if the environment variable $WAIT or $DEBUG is set

func E added in v0.0.2024022328

func E(rest ...any) error

E returns the error.

func Err

func Err[T any](err error) (T, error)

Err returns a zero value and the given error.

func Ignore

func Ignore[T any](T, ...any)

Ignore ignores an error explicitly.

func Let

func Let[T any](err error, fn func() T) T

Let returns the result of the given function if err is nil.

func Let0

func Let0(err error, fn func())

Let0 calls the given function if err is nil and returns nothing.

func Let1

func Let1[T any](err error, fn func() T) T

Let1 is an alias of Let.

func Let2

func Let2[T any, U any](err error, fn func() (T, U)) (T, U)

func Ok

func Ok[T any](value T) (T, error)

Ok returns the given value and nil.

func P added in v0.0.2024022348

func P[T any](v T) *T

P returns a pointer to a copied value.

func PMap added in v0.0.2024022348

func PMap[T any, U any](pt *T, fn func(*T) *U) *U

PMap returns a pointer to the result of the given function.

func PR added in v0.0.2024022348

func PR[T any](ptr *T, err error) *pointerResult[T]

PR returns a pointer + error result context.

func Ptr

func Ptr[T any](v T) *T

func PtrMap

func PtrMap[T any, U any](pt *T, fn func(*T) *U) *U

func R added in v0.0.2024021526

func R[T any](value T, err error) *pointerResult[T]

R returns a value + error result context.

func RecoverPanicObject

func RecoverPanicObject[T comparable](errRef *error, target T, fn func() error)

func RecoverPanicType

func RecoverPanicType[T any](errRef *error, fn func(T) error)

func Ternary

func Ternary[T any](
	cond bool,
	t T,
	f T,
) T

Ternary returns the first value if cond is true, otherwise the second value.

func TernaryF

func TernaryF[T any](
	cond bool,
	t func() T,
	f func() T,
) (ret T)

TernaryF returns the result of the first function if cond is true, otherwise the result of the second function.

func Then

func Then(err error, fn func() error) error

Then calls the given function if err is nil.

func V added in v0.0.2024022328

func V[T any](value T, err error) T

V returns the value. If err is not nil, it panics.

func V0 added in v0.0.2024022328

func V0[T any](first T, rest ...any)

V0 returns no value. If err is not nil, it panics.

func V2 added in v0.0.2024070104

func V2[T any, U any](value1 T, value2 U, err error) (T, U)

V2 returns two values. If err is not nil, it panics.

func V3 added in v0.0.2024070250

func V3[T any, U any, V any](value1 T, value2 U, value3 V, err error) (T, U, V)

V3 returns three values. If err is not nil, it panics.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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