Documentation ¶
Index ¶
- type Result
- func (r Result[T, E]) And(fn func(T) T) Result[T, E]
- func (r Result[T, E]) AndThen(fn func(T) Result[T, E]) Result[T, E]
- func (r Result[T, E]) Err() E
- func (r Result[T, E]) IsErr() bool
- func (r Result[T, E]) IsOk() bool
- func (r Result[T, E]) Unwrap() T
- func (r Result[T, E]) UnwrapOr(value T) T
- func (r Result[T, E]) UnwrapOrDefault() T
- func (r Result[T, E]) UnwrapOrElse(fn func() T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result[T, E any] struct { // contains filtered or unexported fields }
Result represents the result of an operation that is successful or not.
func (Result[T, E]) And ¶ added in v5.23.0
And calls the provided function with the contained value if the result is Ok, returns the Result value otherwise.
func (Result[T, E]) AndThen ¶ added in v5.23.0
AndThen calls the provided function with the contained value if the result is Ok, returns the Result value otherwise.
This differs from `And` in that the provided function returns a Result[T, E] allowing changing of the Option value itself.
func (Result[T, E]) Err ¶
func (r Result[T, E]) Err() E
Err returns the error of the result. To be used after calling IsOK()
func (Result[T, E]) Unwrap ¶
func (r Result[T, E]) Unwrap() T
Unwrap returns the values of the result. It panics if there is no result due to not checking for errors.
func (Result[T, E]) UnwrapOr ¶ added in v5.22.0
func (r Result[T, E]) UnwrapOr(value T) T
UnwrapOr returns the contained Ok value or a provided default.
Arguments passed to UnwrapOr are eagerly evaluated; if you are passing the result of a function call, look to use `UnwrapOrElse`, which can be lazily evaluated.
func (Result[T, E]) UnwrapOrDefault ¶ added in v5.22.0
func (r Result[T, E]) UnwrapOrDefault() T
UnwrapOrDefault returns the contained Ok value or the default value of the type T.
func (Result[T, E]) UnwrapOrElse ¶ added in v5.22.0
func (r Result[T, E]) UnwrapOrElse(fn func() T) T
UnwrapOrElse returns the contained Ok value or computes it from a provided function.