resultext

package
v5.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2024 License: Apache-2.0, MIT Imports: 0 Imported by: 1

Documentation

Index

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 Err

func Err[T, E any](err E) Result[T, E]

Err returns a Result that contains the given error.

func Ok

func Ok[T, E any](value T) Result[T, E]

Ok returns a Result that contains the given values.

func (Result[T, E]) And added in v5.23.0

func (r Result[T, E]) And(fn func(T) T) Result[T, E]

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

func (r Result[T, E]) AndThen(fn func(T) Result[T, E]) Result[T, E]

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

func (r Result[T, E]) IsErr() bool

IsErr returns true if the result is not successful and has an error.

func (Result[T, E]) IsOk

func (r Result[T, E]) IsOk() bool

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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL