gott

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: MPL-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exception

type Exception struct {
	E interface{}
}

Exception is a type encapsulating anything contained in panic. It implements Error() and therefore can be used as error.

func (Exception) Error

func (e Exception) Error() string

type LogLevel

type LogLevel int
const (
	Quiet LogLevel = iota
	Error
	Debug
	Info
)

LogLevel specifies what to log: Quiet logs nothing, Error logs only errors, Debug logs functions that run, Info logs run and skipped functions

type R

type R[T any] struct {
	S        T
	E        error
	LogLevel LogLevel
}

R is a simplification of Either monad. It’s either succesful—when its error is nil—or unsuccessful otherwise.

func (R[T]) Bind

func (r R[T]) Bind(f func(T) (T, error)) R[T]

Bind performs f on the receiver’s success value and assigns the returned value and error to the receiver if it’s is successful. In either case, Bind returns the receiver. Bind operates on functions that return value and error.

func (R[T]) Catch

func (r R[T]) Catch(f func(T) T) (r2 R[T])

Catch performs f on the receiver’s success value and assigns the returned vale to the receiver if it’s successful. If f panics, Catch recovers and stores the value passed to panic in receiver’s error as Exception. In either case, Catch returns the receiver.

func (R[T]) Handle

func (r R[T]) Handle(onSuccess func(T), onError func(error)) R[T]

Handle performs onSuccess on the receiver’s success value if the receiver is successful, or onError on the receiver’s error otherwise. In either case, Handle returns the receiver.

func (R[T]) Map

func (r R[T]) Map(f func(T) T) R[T]

Map performs f on the receiver’s success value and assigns the returned value to the receiver if it’s is successful. In either case, Map returns the receiver. Map operates on functions that are always successful and return only one value.

func (R[T]) Recover

func (r R[T]) Recover(f func(T, error) (T, error)) R[T]

Revover tries to put processing back on the happy track. If receiver is not successful, Recover calls the passed function and assignes the returned value and error to the receiver. In either case, Recover returns the receiver.

func (R[T]) SafeTee

func (r R[T]) SafeTee(f func(T)) R[T]

SafeTee performs f on the receiver’s success value if the receiver is successful. In either case, SafeTee returns the receiver. SafeTee operates on functions that only perform side effects and are always successful.

func (R[T]) Tee

func (r R[T]) Tee(f func(T) error) R[T]

Tee performs f on the receiver’s success value and assigns the returned error to the receiver if it’s is successful. In either case, Tee returns the receiver. Tee operates on functions that only perform side effects and might return an error

Jump to

Keyboard shortcuts

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