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 ¶
- type Result
- func (r Result[T]) IsErr() bool
- func (r Result[T]) IsOk() bool
- func (r Result[T]) Map(mapper func(value T) T) Result[T]
- func (r Result[T]) Unwrap() (T, error)
- func (r Result[T]) Value() (T, error)
- func (r Result[T]) WithDefault(defaultValue T) T
- func (r Result[T]) Zip(mapper func(value T) (T, error)) Result[T]
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 (Result[T]) Map ¶
Map transforms the new value using mapper if changed; otherwise returns Keep.
func (Result[T]) WithDefault ¶
func (r Result[T]) WithDefault(defaultValue T) T
WithDefault returns the value if Ok, otherwise fallback.
Click to show internal directories.
Click to hide internal directories.