From 9b04eeb7a33c0fb9f56f2abcb9fa1483da45fcbf Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Fri, 15 May 2020 10:57:38 +0200 Subject: [PATCH] Added documentation for Action{,Err,s}. --- action.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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 {