Documentation ¶
Index ¶
- func MatchResultR0[O any, X any](result Result[O, X], onOk func(ok O), onError func(err X))
- func MatchResultR1[O any, X any, T0 any](result Result[O, X], onOk func(ok O) T0, onError func(err X) T0) T0
- 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)
- func MatchResultR3[O any, X any, R0, R1, R2 any](result Result[O, X], onOk func(ok O) (R0, R1, R2), ...) (R0, R1, R2)
- func Unwrap[O any, X any](result Result[O, X]) (O, X)
- type Result
- func And[O, O2, X any](res1 Result[O, X], res2 Result[O2, X]) Result[O2, X]
- func AndThen[O, X, O2 any](result Result[O, X], thenFunc func(O) Result[O2, X]) Result[O2, X]
- func Error[O, X any](value X) Result[O, X]
- func MapError[O, X, X2 any](result Result[O, X], mapFn func(X) X2) Result[O, X2]
- func MapOk[O, X, O2 any](result Result[O, X], mapFn func(O) O2) Result[O2, X]
- func MapResultR0[O, X, O2, X2 any](result Result[O, X], mapOkFn func(O) O2, mapErrFn func(X) X2) Result[O2, X2]
- 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)
- func NewFailure(err error) Result[ipld.Builder, ipld.Builder]
- func Ok[O, X any](value O) Result[O, X]
- func Or[O, X, X2 any](res1 Result[O, X], res2 Result[O, X2]) Result[O, X2]
- func OrElse[O, X, X2 any](result Result[O, X], elseFunc func(X) Result[O, X2]) Result[O, X2]
- func Wrap[O any, X comparable](inner func() (O, X)) Result[O, X]
- type Unit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchResultR0 ¶
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
Types ¶
type Result ¶
Result is a golang compatible generic result type
func And ¶
And treats a result as a boolean, returning the second result only if the the first is succcessful
func AndThen ¶
AndThen takes a result and if it is success type, runs an additional function that returns a subsequent result type
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 Or ¶
Or treats a result as a boolean, returning the second result if the first result is an error
func OrElse ¶
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