gott

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MPL-2.0 Imports: 4 Imported by: 9

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 added in v1.1.0

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 Result

type Result struct {
	LogLevel LogLevel
	// contains filtered or unexported fields
}

Result is a simplification of Either monad. It’s either successful—and carries an interface{}—or unsuccessful—and carries an error.

func NewResult

func NewResult(s interface{}) *Result

NewResult creates initial Result passed to functions.

func (*Result) Bind

func (r *Result) Bind(fn func(...interface{}) (interface{}, error)) *Result

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

func (*Result) Catch

func (r *Result) Catch(fn func(...interface{}) interface{}) (result *Result)

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

func (*Result) Finish added in v0.1.1

func (r *Result) Finish() (interface{}, error)

Finish returns the values stored in the receiver.

func (*Result) Handle

func (r *Result) Handle(onSuccess func(...interface{}), onError func(error)) *Result

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 (*Result) Map

func (r *Result) Map(fn func(...interface{}) interface{}) *Result

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

func (*Result) Recover added in v1.1.0

func (r *Result) Recover(fn func(...interface{}) (interface{}, error)) *Result

Revover tries to put processing back on the happy track. If receiver is not successful, Recover calls the passed function and assignes the returned values to the receiver. In either case, Recover returns the receiver. The passed function gets the error (on nil) as the last argument

func (*Result) SafeTee

func (r *Result) SafeTee(fn func(...interface{})) *Result

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

func (*Result) SetLevelLog added in v1.1.1

func (r *Result) SetLevelLog(l LogLevel) *Result

func (*Result) Tee

func (r *Result) Tee(fn func(...interface{}) error) *Result

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

type Tuple added in v1.0.0

type Tuple []interface{}

Tuple is a type encapsulating a slice of interface{}.

Jump to

Keyboard shortcuts

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