Documentation ¶
Index ¶
- type Eitherr
- func FlatMap[R, V any](e Eitherr[R], f FMapper[R, V]) Eitherr[V]
- func FromFallible[R any](r R, err error) Eitherr[R]
- func Left[R any](err error) Eitherr[R]
- func LiftOption[R any](o opt.Option[R], err error) Eitherr[R]
- func Map[R, V any](e Eitherr[R], f funcs.Mapper[R, V]) Eitherr[V]
- func Right[R any](r R) Eitherr[R]
- type FMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Eitherr ¶
type Eitherr[R any] interface { // OrElse returns contained value if this is right; otherwise returns given `other` value. OrElse(other R) R // ForEach executes given procedure for right, skips for left. ForEach(procedure funcs.Procedure[R]) Eitherr[R] // ToErr is nil for right, and error for left ToErr() error // ToOpt converts right to opt.Some, left to opt.None. ToOpt() opt.Option[R] // Map is category unchanging method, variant of Map function. Map(mapper funcs.Mapper[R, R]) Eitherr[R] // FlatMap is category unchanging method, variant of FlatMap function. FlatMap(fMap FMapper[R, R]) Eitherr[R] }
Either represents value that can be of one of two types, left or right. With that said, left should be generic over some L, right - over R:
type Either[L, R any] interface {} type right[R any] struct { R } type left[L any] struct { L }
However, staying on a practical side, and taking into account following facts:
- left type L can be simplified to error
- golang type system makes it no simple using complex generic types
- things may change in the future, and left may want to reclaim its type
Either is simplified to
type Eitherr[R any] interface {} type right[R any] struct { R } type left[R any] struct { error }
with all auxiliary functions type signatures became simplified as well. (However, there will be no Swap function)
func FlatMap ¶
FlatMap returns right with result of applying f to R, if this is right; otherwise it returns unchanged left.
func FromFallible ¶
Click to show internal directories.
Click to hide internal directories.