Documentation
¶
Overview ¶
Package result provides a generic Result type for Go inspired by Rust's Result<T, E>.
Index ¶
- func Match[T any, U any](r Result[T], onOk func(T) U, onErr func(error) U) U
- type Result
- func All[T any](results []Result[T]) Result[[]T]
- func Err[T any](err error) Result[T]
- func Errf[T any](format string, args ...any) Result[T]
- func FlatMap[T any, U any](r Result[T], fn func(T) Result[U]) Result[U]
- func Map[T any, U any](r Result[T], fn func(T) U) Result[U]
- func Ok[T any](value T) Result[T]
- func Try[T any](fn func() (T, error)) Result[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result represents either a success value (Ok) or an error value (Err).
func All ¶
All collects a slice of Results into a Result containing a slice of values. Returns the first error encountered.
func (Result[T]) Unwrap ¶
func (r Result[T]) Unwrap() T
Unwrap returns the success value or panics if the Result is an error.
func (Result[T]) UnwrapOr ¶
func (r Result[T]) UnwrapOr(def T) T
UnwrapOr returns the success value or the provided default.
func (Result[T]) UnwrapOrElse ¶
UnwrapOrElse returns the success value or calls the provided function.
Click to show internal directories.
Click to hide internal directories.