package resultext
import "github.com/go-playground/pkg/v5/values/result"
Index ¶
- type Result
- func Err[T, E any](err E) Result[T, E]
- func Ok[T, E any](value T) Result[T, E]
- 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
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 Err ¶
Err returns a Result that contains the given error.
func Ok ¶
Ok returns a Result that contains the given values.
func (Result[T, E]) And ¶
And calls the provided function with the contained value if the result is Ok, returns the Result value otherwise.
func (Result[T, E]) AndThen ¶
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]) IsErr ¶
IsErr returns true if the result is not successful and has an error.
func (Result[T, E]) IsOk ¶
IsOk returns true if the result is successful with no error.
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 ¶
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 ¶
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 ¶
func (r Result[T, E]) UnwrapOrElse(fn func() T) T
UnwrapOrElse returns the contained Ok value or computes it from a provided function.
Source Files ¶
- Version
- v5.30.0 (latest)
- Published
- Jun 1, 2024
- Platform
- linux/amd64
- Last checked
- 9 hours ago –
Tools for package owners.