try

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 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 FMapper

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

type Try

type Try[R any] interface {
	IsSuccess() bool

	// 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]

	// 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]

	// 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]
}

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