maybedoer

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: Zlib Imports: 1 Imported by: 0

Documentation

Overview

Package maybedoer contains a pipeline of actions that might fail. If any action in the chain fails, no further actions take place and the error becomes the pipeline error.

MIT License

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doer

type Doer func(context.Context) error

Doer is a function that implements a fallible action that can be done.

type Impl

type Impl struct {
	Doers []Doer
	// contains filtered or unexported fields
}

Impl sequences a set of actions to be performed via calls to `Maybe` such that any previous error prevents new actions from being performed.

This is, conceptually, just a go-ification of the Maybe monoid, but defined to the error type in Go.

func (*Impl) Do

func (c *Impl) Do(ctx context.Context) error

Do executes the list of doers, right-folding the functions and seeing if one returns an error. This is semantically identical to Data.Monoid.First in Haskell, but specific to the error type in Go. Ideally this could be generalized to any pointer-like datatype in Go, but Rob Pike says we can't have nice things.

See the Haskell documentation for Data.Monad.First for more information: http://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Monoid.html#t:First

func (*Impl) Error

func (c *Impl) Error() error

Error returns the first error encountered in the Error chain.

func (*Impl) Maybe

func (c *Impl) Maybe(ctx context.Context, f func(ctx context.Context) error)

Maybe performs `f` if no previous call to a Maybe'd action resulted in an error

Jump to

Keyboard shortcuts

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