result

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package result provides a Rust-style Result type for propagating success or error values.

Package result provides a container for values or errors with ergonomic helpers inspired by languages like Rust and TypeScript.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

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

Result holds either a value of type T or an error. If err is nil, the Result is successful; otherwise it is a failure.

func Bind

func Bind[A any, B any](r Result[A], mapper func(value A) Result[B]) Result[B]

Bind maps Ok[A] to Result[B] using mapper, or passes through Err.

func Err

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

Err constructs a failed Result with the provided error.

func From

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

From constructs an Result from a (value, err) pair.

func Map

func Map[A any, B any](r Result[A], mapper func(value A) B) Result[B]

Map maps Ok[A] to Ok[B] using mapper, or passes through Err.

func Ok

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

Ok builds an Ok Result with the provided value.

func (Result[T]) IsErr

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

IsErr reports whether the Result is a failure.

func (Result[T]) IsOk

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

IsOk reports whether the Result is successful.

func (Result[T]) Map

func (r Result[T]) Map(mapper func(value T) T) Result[T]

Map transforms the new value using mapper if changed; otherwise returns Keep.

func (Result[T]) Unwrap

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

Unwrap returns the value and error.

func (Result[T]) Value

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

Value returns the new value and whether it represents a failure.

func (Result[T]) WithDefault

func (r Result[T]) WithDefault(defaultValue T) T

WithDefault returns the value if Ok, otherwise fallback.

func (Result[T]) Zip

func (r Result[T]) Zip(mapper func(value T) (T, error)) Result[T]

Zip maps the new value using a mapper that returns the pair (value, changed).

Jump to

Keyboard shortcuts

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