Documentation
¶
Overview ¶
Package result implements a R{value, error} "sum type" that has a value only when error is nil.
Note that in many cases, it is more idiomatic for a function to return a naked (value, error). Use WrapFunc to convert such a function to return a R result type.
Index ¶
- func Applicator[X any, Y any](f R[func(x X) Y]) func(x X) R[Y]
- func Compose[X any, Y any, Z any](xy func(R[X]) R[Y], yz func(R[Y]) R[Z]) func(R[X]) R[Z]
- func FlatMap[X any, Y any](f func(x X) R[Y]) func(x2 R[X]) R[Y]
- func Lift[X any, Y any](f func(x X) Y) func(x X) R[Y]
- func Map[X any, Y any](f func(x X) Y) func(x2 R[X]) R[Y]
- func UnwrapFunc[X any, Y any](f func(x X) R[Y]) func(x X) (Y, error)
- func WrapFunc[X any, Y any](f func(x X) (Y, error)) func(x X) R[Y]
- type R
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Applicator ¶ added in v2.2.0
Applicator turns function "R[f]: X => Y" into "f: X => R[Y]".
func Compose ¶ added in v2.2.0
Compose takes two functions of the form "xy: R[X] => R[Y]" and "yz: R[Y] => R[Z]" and returns a function "xz(R[X]) => R[Z]".
func Lift ¶
Lift converts a function of the form "f: X => Y" to the form "f: X => R[Y]" where R[Y] == Some(y).
func UnwrapFunc ¶
UnwrapFunc converts a function of the form "f: X => R[Y]" to the form "f: X => (Y, error)".
Types ¶
type R ¶ added in v2.2.0
R is a (value, error) "sum type" that has a value only when error is nil.
func New ¶
New returns a R. It is syntax sugar for R{value, error}. If error is a known constant, use Some or Error instead.
func (R[V]) Else ¶ added in v2.2.0
func (r R[V]) Else(v V) V
Else returns R.value if not an error, otherwise returns the provided argument instead.
func (R[V]) JoinError ¶ added in v2.7.0
JoinError returns a new Error based on an existing R. If the existing R is not an error, returns Error(err). Otherwise, returns Error(errors.Join(existingError, err)).
func (R[V]) Must ¶ added in v2.2.0
func (r R[V]) Must() V
Must returns a R's value. If the R is an error, panics.
func (R[V]) MustError ¶ added in v2.2.0
MustError returns a R's error. Panics if the R is not an error.