try

package
v0.0.59 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FMapper

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

type GoIdiomatic added in v0.0.48

type GoIdiomatic[R any] interface {
	Get() (R, error)
}

type Is added in v0.0.39

type Is[R any] interface {
	IsFailure() bool
	IsSuccess() bool
}

type Monadic added in v0.0.39

type Monadic[R any] interface {
	// OrElse returns contained value if this is success; otherwise returns given `other` value.
	OrElse(other R) R

	// ForEach executes given procedure for success, skips for failure.
	ForEach(procedure funcs.Procedure[R]) Try[R]

	// Proc does nothing for left; it turns success to failure on proc error
	Proc(proc funcs.FallibleFunction[R]) Try[R]
	ProcFailure(proc funcs.Procedure[error]) Try[R]

	// Map is category unchanging method, variant of Map function.
	Map(mapper funcs.Mapper[R, R]) Try[R]
	MapFailure(lm funcs.Mapper[error, error]) Try[R]

	// FlatMap is category unchanging method, variant of FlatMap function.
	FlatMap(fMap FMapper[R, R]) Try[R]
}

type To added in v0.0.39

type To[R any] interface {
	// ToErr is nil for success, and error for failure
	ToErr() error

	// ToOpt converts success to opt.Some, failure to opt.None.
	ToOpt() opt.Option[R]
}

type Try

type Try[R any] interface {
	Is[R]
	To[R]
	Monadic[R]
	GoIdiomatic[R]
}

Try is like Either, with left type simplified to error (Basically, Try[T].ToEither() :: Either[error, T]).

func Failure

func Failure[R any](err error) Try[R]

func FlatMap

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

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

func LiftOption

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

func Map

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

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

func Success

func Success[R any](r R) Try[R]

func Trie

func Trie[R any](r R, err error) Try[R]

Jump to

Keyboard shortcuts

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