diff --git a/action.go b/action.go index 7c75ab1..17b3d6b 100644 --- a/action.go +++ b/action.go @@ -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 {