Skip to content

Index

func Ignore

go
func Ignore[T any](val T, err error) T

Ignore is a helper that wraps a call to a function returning value and error and ignores if the error is non-nil.

func IgnoreRuntime

go
func IgnoreRuntime(val any, err error) any

IgnoreRuntime is a runtime version of errorsx.Ignore().

func Must

go
func Must[T any](val T, err error) T

Must is a helper that wraps a call to a function returning value and error and panics if the error is non-nil.

func MustRuntime

go
func MustRuntime(val any, err error) any

MustRuntime is a runtime version of errorsx.Must().

type Result

Result is a generic type that wraps a value and an error. It also provides a set of methods to resolve/unwrap underlying value with a specific value/error handling.

go
type Result[T any] struct {
    // contains filtered or unexported fields
}

func Wrap

go
func Wrap[T any](val T, err error) Result[T]

Wrap wraps a value and an error into a Result

func (Result[T]) Catch

go
func (r Result[T]) Catch(fn func(error)) Result[T]

Catch executes the provided function if an error is present

func (Result[T]) Error

go
func (r Result[T]) Error() error

Error getter

func (Result[T]) Must

go
func (r Result[T]) Must() T

Must returns the value if no error is present, otherwise panics with the error

func (Result[T]) Then

go
func (r Result[T]) Then(fn func(T)) Result[T]

Then executes the provided function if no error is present

func (Result[T]) Value

go
func (r Result[T]) Value() T

Value getter

func (Result[T]) ValueOr

go
func (r Result[T]) ValueOr(def T) T

ValueOr returns the value if no error is present, otherwise returns the provided default value

Generated by gomarkdoc