results

package
v0.0.0-...-b7aacc1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 0 Imported by: 2

Documentation

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 wraps the idiomatic tuple of (value, error)

func FromErr

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

FromErr returns a result with error

func FromOk

func FromOk[T any](ok T) Result[T]

FromOk returns a Result without error

func New

func New[T any](ok T, err error) Result[T]

New wraps a (value, error) tuple in a Result

func Pipe

func Pipe[T1, T2 any](res Result[T1], f func(T1) Result[T2]) Result[T2]

Pipe only executes f if res.Err() is nil, returns the original error otherwise

func Try

func Try[T1, T2 any](res Result[T1], f func(T1) T2) Result[T2]

Try transforms the value of Result to the new type if OK, returns the original error otherwise

func (Result[T]) Err

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

Err returns an error, Ok is invalid in that case

func (Result[T]) Ok

func (res Result[T]) Ok() T

Ok returns a value if Err is nil

Jump to

Keyboard shortcuts

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