eitherr

package
v0.0.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2022 License: CC0-1.0 Imports: 2 Imported by: 0

Documentation

Index

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:

  1. left type L can be simplified to error
  2. golang type system makes it no simple using complex generic types
  3. 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

func FlatMap[R, V any](e Eitherr[R], f FMapper[R, V]) Eitherr[V]

FlatMap returns right with result of applying f to R, if this is right; otherwise it returns unchanged left.

func FromFallible

func FromFallible[R any](r R, err error) Eitherr[R]

func Left

func Left[R any](err error) Eitherr[R]

func LiftOption

func LiftOption[R any](o opt.Option[R], err error) Eitherr[R]

func Map

func Map[R, V any](e Eitherr[R], f funcs.Mapper[R, V]) Eitherr[V]

Map returns right containing the result of applying f to m if it's not left; otherwise it returns unchanged left.

func Right[R any](r R) Eitherr[R]

type FMapper

type FMapper[R, V any] funcs.Mapper[R, Eitherr[V]]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL