result

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0, MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchResultR0

func MatchResultR0[O any, X any](
	result Result[O, X],
	onOk func(ok O),
	onError func(err X),
)

MatchResultR1 handles a result with a functions that has no return value

func MatchResultR1

func MatchResultR1[O any, X any, T0 any](
	result Result[O, X],
	onOk func(ok O) T0,
	onError func(err X) T0,
) T0

MatchResultR1 handles a result with functions returning one value

func MatchResultR2

func MatchResultR2[O any, X any, R0, R1 any](
	result Result[O, X],
	onOk func(ok O) (R0, R1),
	onError func(err X) (R0, R1),
) (R0, R1)

MatchResultR2 handles a result with functions returning two values

func MatchResultR3

func MatchResultR3[O any, X any, R0, R1, R2 any](
	result Result[O, X],
	onOk func(ok O) (R0, R1, R2),
	onError func(err X) (R0, R1, R2),
) (R0, R1, R2)

MatchResultR3 handles a result with functions returning 3 values

func Unwrap

func Unwrap[O any, X any](result Result[O, X]) (O, X)

Types

type Result

type Result[O any, X any] interface {
	// contains filtered or unexported methods
}

Result is a golang compatible generic result type

func And

func And[O, O2, X any](res1 Result[O, X], res2 Result[O2, X]) Result[O2, X]

And treats a result as a boolean, returning the second result only if the the first is succcessful

func AndThen

func AndThen[O, X, O2 any](result Result[O, X], thenFunc func(O) Result[O2, X]) Result[O2, X]

AndThen takes a result and if it is success type, runs an additional function that returns a subsequent result type

func Error

func Error[O, X any](value X) Result[O, X]

Error returns an error result type

func MapError

func MapError[O, X, X2 any](result Result[O, X], mapFn func(X) X2) Result[O, X2]

MapError transforms an error result while leaving a success result unchanged

func MapOk

func MapOk[O, X, O2 any](result Result[O, X], mapFn func(O) O2) Result[O2, X]

MapOk transforms a successful result while leaving an error result unchanged

func MapResultR0

func MapResultR0[O, X, O2, X2 any](result Result[O, X], mapOkFn func(O) O2, mapErrFn func(X) X2) Result[O2, X2]

MapResultR0 transforms a result -- with seperate functions to modify both the success type and error type

func MapResultR1

func MapResultR1[O, X, O2, X2, R1 any](result Result[O, X], mapOkFn func(O) (O2, R1), mapErrFn func(X) (X2, R1)) (Result[O2, X2], R1)

MapResultR1 transforms a result -- with seperate functions to modify both the success type and error type that also returna one additional value

func NewFailure

func NewFailure(err error) Result[ipld.Builder, ipld.Builder]

func Ok

func Ok[O, X any](value O) Result[O, X]

Ok returns a success result type

func Or

func Or[O, X, X2 any](res1 Result[O, X], res2 Result[O, X2]) Result[O, X2]

Or treats a result as a boolean, returning the second result if the first result is an error

func OrElse

func OrElse[O, X, X2 any](result Result[O, X], elseFunc func(X) Result[O, X2]) Result[O, X2]

OrElse takes a result and if it is an error type, runs an additional function that returns a subsequent result type

func Wrap

func Wrap[O any, X comparable](inner func() (O, X)) Result[O, X]

Wrap wraps a traditional golang pattern for two value functions with the second being an error where the zero value indicates absence, converting it to a result

type Unit

type Unit interface{}

https://en.wikipedia.org/wiki/Unit_type

Directories

Path Synopsis
ok

Jump to

Keyboard shortcuts

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