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