Documentation
¶
Index ¶
- type Result
- func (self Result[T]) And(res Result[T]) Result[T]
- func (self Result[T]) AsRawParts() (data T, err error)
- func (self Result[T]) Error() error
- func (self Result[T]) IfErr(f func(error))
- func (self Result[T]) IfOk(f func(T))
- func (self Result[T]) IsErr() bool
- func (self Result[T]) IsOk() bool
- func (self Result[T]) Map(fn func(T) T) Result[T]
- func (self Result[T]) Or(res Result[T]) Result[T]
- func (self Result[T]) String() string
- func (self Result[T]) Value() T
- func (self Result[T]) ValueOr(v T) T
- func (self Result[T]) ValueOrElse(f func() T) T
- func (self Result[T]) ValueOrZero() T
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 (Result[T]) AsRawParts ¶ added in v0.2.1
AsRawParts return tuple of value ptr and error.
func (Result[T]) IfOk ¶
func (self Result[T]) IfOk(f func(T))
IfOk call the function if the Result is Ok.
func (Result[T]) Map ¶ added in v0.3.0
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]) 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.