Documentation ¶
Index ¶
- func Exists[L, R any](predicate func(right R) bool) func(Either[L, R]) bool
- func FromOption[L, R any](onNone func() L) func(o opt.Option[R]) Either[L, R]
- func FromPredicate[L, R any](predicate func(value R) bool, onLeft func() L) func(R) Either[L, R]
- func GetOrElse[L, R any](onLeft func(left L) R) func(Either[L, R]) R
- func IsLeft[L, R any](e Either[L, R]) bool
- func IsRight[L, R any](e Either[L, R]) bool
- func Map[L, R, T any](onRight func(right R) T) func(Either[L, R]) Either[L, T]
- func MapLeft[L, R, T any](fn func(left L) T) func(Either[L, R]) Either[T, R]
- func Match[L, R, T any](onLeft func(left L) T, onRight func(right R) T) func(Either[L, R]) T
- type Either
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exists ¶
Returns `false` if `Left` or returns the boolean result of the application of the given predicate to the `Right` value
func FromOption ¶
Constructor of Either from an Option. Returns a Left in case of None storing the callback return value as the error argument Returns a Right in case of Some with the option value.
func FromPredicate ¶
Constructor of Either from a predicate. Returns a Left if the predicate function over the value return false. Returns a Right if the predicate function over the value return true.
func GetOrElse ¶
Extracts the value out of the Either, if it exists. Otherwise returns the result of the callback function that takes the error as argument.
Types ¶
type Either ¶
type Either[L, R any] struct { // contains filtered or unexported fields }
Base struct
func FromError ¶
Constructor of Either from any couple of mutually exclusive `value` and `error`. Returns a Left in case we have an error, Right if we have a value and error is nil.
func FromErrorFn ¶
Constructor of Either from any lazy function that returns a couple of mutually exclusive `value` and `error`. Returns a Left in case we have a return error, Right if we have return value and error is nil.