Help us shape the future of Go! Take the 2026 Go Developer Survey

result

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 3 Imported by: 6

Documentation

Overview

Package result provides a Result type that can contain a value or an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go[T any](f func() (T, error)) chan Result[T]

Go runs a function in a goroutine and returns a channel that will receive the Result.

Types

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

A Result type is a type that can contain an error or a value.

func Err

func Err[T any](err error) Result[T]

Err returns a Result that contains an error.

func Errf added in v0.14.0

func Errf[T any](format string, args ...any) Result[T]

Errf returns a Result that contains a formatted error.

func Errorf deprecated

func Errorf[T any](format string, args ...any) Result[T]

Errorf returns a Result that contains a formatted error.

Deprecated: Use Errf instead.

func From added in v0.14.0

func From[T any](value T, err error) Result[T]

From returns a Result that contains a value or an error.

It can be used to convert a function that returns a value and an error into a Result.

func Map added in v0.20.0

func Map[L, R any](l Result[L], mapper func(L) (R, error)) Result[R]

Map a Result[L] to Result[R]. If Result[L] is an error mapper will not be called and the result will be an error.

func Ok

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

Ok returns a Result that contains a value.

func Outcome deprecated

func Outcome[T any](value T, err error) Result[T]

Outcome returns a Result that contains a value or an error.

It can be used to convert a function that returns a value and an error into a Result.

Deprecated: Use From instead.

func (Result[T]) Default

func (r Result[T]) Default(value T) T

Default returns the Result value if it is present, otherwise it returns the value passed.

func (Result[T]) Err

func (r Result[T]) Err() error

Err returns the error, if any.

func (Result[T]) Get

func (r Result[T]) Get() (T, bool)

Get returns the value and a boolean indicating whether the value is present.

func (Result[T]) GoString

func (r Result[T]) GoString() string

func (Result[T]) MarshalJSON

func (r Result[T]) MarshalJSON() ([]byte, error)

func (Result[T]) Result added in v0.14.0

func (r Result[T]) Result() (T, error)

Result returns the underlying value and error.

func (Result[T]) String

func (r Result[T]) String() string

func (*Result[T]) UnmarshalJSON

func (r *Result[T]) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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