Documentation
¶
Overview ¶
Package dry is all about not repeating yourself by using rough approximations of some of the concepts provided by dry-rb.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result interface { // Wrapped returns the value that is wrapped by a Result. Wrapped() Value // Success returns a boolean. If the result is a success, it is true. // Otherwise, it is false. Success() bool // Failure returns a boolean. If the result is a failure, it is true. // Otherwise, it is false. Failure() bool // Value returns the value that is wrapped by a Success result. Value() Value // Error returns the value that is wrapped by a Failure result. Error() Value }
Result is (not really) a monad that is used to model the result of an operation. It can be either a Success or a Failure that wraps a value.
type Step ¶
Step is a function that can be used as a step in a Transaction.
Any given step is passed a Value, and it must return a Result.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a model that describes a multi-step process that can fail during any given step.
func NewTransaction ¶
func NewTransaction(steps ...Step) *Transaction
NewTransaction returns a new Transaction.
If an optional list of steps is provided, the resulting transaction includes those steps.
Otherwise, the transaction is a no-op and the Step method should be used to add functionality.
func (*Transaction) Call ¶
func (transaction *Transaction) Call(value Value) Result
Call takes a Value, which is then propagated through the list of steps associated with the transaction.
The result of each step is passed as input to its subsequent step, and the result of the final step is returned.
If any step results in a Failure, that failure is immediately returned and steps after the failing step are skipped.
func (*Transaction) Step ¶
func (transaction *Transaction) Step(step Step) *Transaction
Step takes a step function and adds it to the list of steps to perform when the associated transaction is called.
For the sake of those who prefer method chains to individual calls, the modified transaction is returned.