Documentation
¶
Overview ¶
Package result - Because nil checks are so last century
Index ¶
- type Option
- type Pair
- type Result
- func Collect[T any](results []Result[T]) Result[[]T]
- func Err[T any](err error) Result[T]
- func FlatMap[T, U any](r Result[T], fn func(T) Result[U]) Result[U]
- func FromOption[T any](opt Option[T], err error) Result[T]
- func Map[T, U any](r Result[T], fn func(T) U) Result[U]
- func NewResult[T any](value T, err error) Result[T]
- func Ok[T any](value T) Result[T]
- func Try[T any](fn func() T) Result[T]
- func Zip[T, U any](r1 Result[T], r2 Result[U]) Result[Pair[T, U]]
- func (r Result[T]) AndThen(fn func(T) error) Result[T]
- func (r Result[T]) Err() error
- func (r Result[T]) Expect(msg string) T
- func (r Result[T]) ExpectErr(msg string) error
- func (r Result[T]) Filter(predicate func(T) bool) Result[T]
- func (r Result[T]) Inspect(fn func(T)) Result[T]
- func (r Result[T]) InspectErr(fn func(error)) Result[T]
- func (r Result[T]) IsErr() bool
- func (r Result[T]) IsOk() bool
- func (r Result[T]) Match(ok func(T), err func(error))
- func (r Result[T]) OrElse(fn func() Result[T]) Result[T]
- func (r Result[T]) Unwrap() (T, error)
- func (r Result[T]) UnwrapErr() error
- func (r Result[T]) UnwrapOr(defaultValue T) T
- func (r Result[T]) UnwrapOrDefault() T
- func (r Result[T]) UnwrapOrElse(fn func(error) T) T
- func (r Result[T]) UnwrapOrPanic() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v1.1.27
type Option[T any] struct { // contains filtered or unexported fields }
Option represents a value that may or may not exist
func (Option[T]) UnwrapOr ¶ added in v1.1.27
func (o Option[T]) UnwrapOr(defaultValue T) T
UnwrapOr returns the contained value or a default
func (Option[T]) UnwrapOrPanic ¶ added in v1.1.27
func (o Option[T]) UnwrapOrPanic() T
UnwrapOrPanic returns the contained value or panics
type Pair ¶ added in v1.1.27
type Pair[T, U any] struct { First T Second U }
Pair holds two values of potentially different types
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result represents a value that might exist Or might be busy generating stack traces
func FromOption ¶ added in v1.1.27
FromOption converts an Option to a Result with custom error
func (Result[T]) ExpectErr ¶
ExpectErr returns the error or panics because you expected failure and got success (how dare you succeed?)
func (Result[T]) Filter ¶ added in v1.1.27
Filter turns success into failure if a condition isn't met
func (Result[T]) InspectErr ¶ added in v1.1.27
InspectErr lets you peek at failure without changing it
func (Result[T]) UnwrapErr ¶
UnwrapErr returns the error or panics because success wasn't in the plan
func (Result[T]) UnwrapOr ¶
func (r Result[T]) UnwrapOr(defaultValue T) T
UnwrapOr returns the value or your backup plan
func (Result[T]) UnwrapOrDefault ¶
func (r Result[T]) UnwrapOrDefault() T
UnwrapOrDefault returns whatever value your type holds.
func (Result[T]) UnwrapOrElse ¶
UnwrapOrElse returns the value or makes you work for a default
func (Result[T]) UnwrapOrPanic ¶
func (r Result[T]) UnwrapOrPanic() T
UnwrapOrPanic returns the value or throws in the towel