result

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 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[T any] struct {
	// contains filtered or unexported fields
}

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

func Err

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

Err create a new Result from an error.

func Errorf added in v0.2.1

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

Errorf create a new Result from a formatted error.

func FromPair added in v0.3.0

func FromPair[T any](data T, err error) Result[T]

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

func Map

func Map[T, U any](res Result[T], f func(T) U) Result[U]

func Ok

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

Ok create a new Result from a value.

func (Result[T]) And

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

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

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

func (self Result[T]) AsRawParts() (data T, err error)

AsRawParts return tuple of value ptr and error.

func (Result[T]) Error

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

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

func (Result[T]) IfErr

func (self Result[T]) IfErr(f func(error))

IfErr call the function if the Result is Err.

func (Result[T]) IfOk

func (self Result[T]) IfOk(f func(T))

IfOk call the function if the Result is Ok.

func (Result[T]) IsErr

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

IsErr returns true if the Result is Err.

func (Result[T]) IsOk

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

IsOk returns true if the Result is Ok.

func (Result[T]) Map added in v0.3.0

func (self Result[T]) Map(fn func(T) T) Result[T]

Map returns a new Result from the result of applying the given function to the value of self if ok, else return err.

FIXME: for now, go doesn't support type parameter on method, so we have to use the same type parameter on the method.

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[T]) String added in v0.1.1

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

String implements fmt.Stringer.

func (Result[T]) Value

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

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

func (Result[T]) ValueOr added in v0.3.0

func (self Result[T]) ValueOr(v T) T

ValueOr returns the value of the Result if it is Ok, otherwise return the given value.

func (Result[T]) ValueOrElse added in v0.3.0

func (self Result[T]) ValueOrElse(f func() T) T

ValueOrElse returns the value of the Result if it is Ok, otherwise return the result of calling the given function.

func (Result[T]) ValueOrZero added in v0.3.0

func (self Result[T]) ValueOrZero() T

ValueOrZero returns the value of the Result if it is Ok, otherwise return the zero value of the type of the Result.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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