result

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

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

Result is a type that represents either a value or an error.

func Err

func Err[Ok any](err error) Result[Ok]

Err create a new Result from an error.

func Errorf added in v0.2.1

func Errorf[Ok any](format string, args ...any) Result[Ok]

Errorf create a new Result from a formatted error.

func Map

func Map[A, B any](result Result[A], transformer func(A) B) Result[B]

func Of

func Of[Ok any](data Ok, err error) Result[Ok]

Of create a new Result from a value or an error.

func Ok

func Ok[Ok any](data Ok) Result[Ok]

Ok create a new Result from a value.

func (Result[Ok]) And

func (self Result[Ok]) And(res Result[Ok]) Result[Ok]

And return self if self is error, otherwise return other.

func (Result[Ok]) AsRawParts added in v0.2.1

func (self Result[Ok]) AsRawParts() (*Ok, error)

AsRawParts return tuple of value ptr and error.

func (Result[Ok]) Error

func (self Result[Ok]) Error() error

Error unwrap the error of the Result, panic if the Result is Ok.

func (Result[Ok]) IfErr

func (self Result[Ok]) IfErr(consume func(error))

IfErr call the function if the Result is Err.

func (Result[Ok]) IfOk

func (self Result[Ok]) IfOk(consume func(Ok))

IfOk call the function if the Result is Ok.

func (Result[Ok]) IsErr

func (self Result[Ok]) IsErr() bool

IsErr returns true if the Result is Err.

func (Result[Ok]) IsOk

func (self Result[Ok]) IsOk() bool

IsOk returns true if the Result is Ok.

func (Result[Ok]) Match

func (self Result[Ok]) Match(consumeOk func(Ok), consumeErr func(error))

Match call consumeOk if the Result is Ok, otherwise call consumeErr.

func (Result[T]) Or

func (self Result[T]) Or(res Result[T]) Result[T]

Or return self if self is ok, otherwise return other.

func (Result[Ok]) String added in v0.1.1

func (self Result[Ok]) String() string

func (Result[Ok]) Value

func (self Result[Ok]) Value() Ok

Value unwrap the value of the Result, panic if the Result is Err.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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