Documentation ¶
Index ¶
- type Exception
- type LogLevel
- type Result
- func (r *Result) Bind(fn func(...interface{}) (interface{}, error)) *Result
- func (r *Result) Catch(fn func(...interface{}) interface{}) (result *Result)
- func (r *Result) Finish() (interface{}, error)
- func (r *Result) Handle(onSuccess func(...interface{}), onError func(error)) *Result
- func (r *Result) Map(fn func(...interface{}) interface{}) *Result
- func (r *Result) Recover(fn func(...interface{}) (interface{}, error)) *Result
- func (r *Result) SafeTee(fn func(...interface{})) *Result
- func (r *Result) SetLevelLog(l LogLevel) *Result
- func (r *Result) Tee(fn func(...interface{}) error) *Result
- type Tuple
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.
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 ¶
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 ¶
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) Handle ¶
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 ¶
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
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 ¶
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.