Added documentation for Action{,Err,s}.
This commit is contained in:
parent
893bf513ad
commit
9b04eeb7a3
@ -1,7 +1,9 @@
|
||||
package zntg
|
||||
|
||||
// Action is a method without arguments or return values.
|
||||
type Action func()
|
||||
|
||||
// Err converts the Action to an ActionErr.
|
||||
func (a Action) Err() ActionErr {
|
||||
return func() error {
|
||||
a()
|
||||
@ -9,24 +11,30 @@ func (a Action) Err() ActionErr {
|
||||
}
|
||||
}
|
||||
|
||||
// ActionErr is a method that only returns an error.
|
||||
type ActionErr func() error
|
||||
|
||||
// Actions is a slice of ActionErr's.
|
||||
type Actions []ActionErr
|
||||
|
||||
// Add adds an Action and returns the new list of Actions.
|
||||
func (a Actions) Add(fn Action) Actions {
|
||||
return a.AddErr(fn.Err())
|
||||
}
|
||||
|
||||
// AddErr adds an ActionErr and return the new list of Actions.
|
||||
func (a Actions) AddErr(fn ActionErr) Actions {
|
||||
return append(a, fn)
|
||||
}
|
||||
|
||||
// Do executes all actions.
|
||||
func (a Actions) Do() {
|
||||
for _, a := range a {
|
||||
a()
|
||||
}
|
||||
}
|
||||
|
||||
// DoErr executes all actions but stops on the first action that returns an error.
|
||||
func (a Actions) DoErr() error {
|
||||
for _, a := range a {
|
||||
if err := a(); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user