Documentation
¶
Overview ¶
Package either provides a sum type representing a value of one of two types.
Convention: Left represents failure/error, Right represents success. Mnemonic: "Right is right" (correct).
Either is right-biased: Map operates on the Right value only.
Index ¶
- func Fold[L, R, T any](e Either[L, R], onLeft func(L) T, onRight func(R) T) T
- type Either
- func (e Either[L, R]) Get() (_ R, _ bool)
- func (e Either[L, R]) GetLeft() (_ L, _ bool)
- func (e Either[L, R]) GetOrElse(defaultVal R) R
- func (e Either[L, R]) IsLeft() bool
- func (e Either[L, R]) IsRight() bool
- func (e Either[L, R]) LeftOrElse(defaultVal L) L
- func (e Either[L, R]) Map(fn func(R) R) Either[L, R]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Either ¶
type Either[L, R any] struct { // contains filtered or unexported fields }
Either represents a value of one of two types. Convention: Left for failure, Right for success.
func (Either[L, R]) GetOrElse ¶
func (e Either[L, R]) GetOrElse(defaultVal R) R
GetOrElse returns the Right value, or defaultVal if Left.
func (Either[L, R]) LeftOrElse ¶
func (e Either[L, R]) LeftOrElse(defaultVal L) L
LeftOrElse returns the Left value, or defaultVal if Right.
Click to show internal directories.
Click to hide internal directories.