Documentation
¶
Index ¶
- Variables
- func If[Out, T any](r Result[T], okFn func(T) Out, errFn func(error) Out) Out
- type Result
- func AndThen[T, U any](r Result[T], fn func(T) Result[U]) Result[U]
- func Err[T any](err error) Result[T]
- func FlatMap[T, U any](r Result[T], fn func(T) Result[U]) Result[U]
- func Map[T, U any](r Result[T], fn func(T) U) Result[U]
- func Map2[T, U, V any](r Result[T], s Result[U], fn func(T, U) V) Result[V]
- func Map3[T, U, V, W any](r Result[T], s Result[U], t Result[V], fn func(T, U, V) W) Result[W]
- func Ok[T any](value T) Result[T]
- func (r Result[T]) Err() error
- func (r Result[T]) Expect(panicMsg string) T
- func (r Result[T]) ExpectErr(panicMsg string) error
- func (r Result[T]) IsErr() bool
- func (r Result[T]) IsOk() bool
- func (r Result[T]) MapError(fn func(e error) error) Result[T]
- func (r Result[T]) Ok(out *T) error
- func (r Result[T]) Unwrap() T
- func (r Result[T]) UnwrapOr(defaultValue T) T
- func (r Result[T]) UnwrapOrElse(fn func(error) T) T
- func (r Result[T]) Value() option.Option[T]
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrEmptyResult = fmt.Errorf("result is error but error was nil")
Functions ¶
Types ¶
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result[T] is a generic pseudo-enum, used for returning results with errors. The result type eliminates the need to return nil pointers, sentinal type zero values, or partial results when an error has occured. Instead, the result type can be in one of two states: Ok(T) or Err(error).
func (Result[T]) Err ¶
If IsErr returns true, Err is guaranteed to return an error value. If Result[T] was initialised as a zero value, or if it was initilised as Err(nil), then this function will return an ErrEmptyResult.
func (Result[T]) IsErr ¶
A Result[T] is considered to be in an error state if there is no value. IsErr will always be opposite to IsOk.
func (Result[T]) UnwrapOrElse ¶
Click to show internal directories.
Click to hide internal directories.