Skip to content

Commit

Permalink
Merge pull request #648 from iotaledger/feat/batch-reverse
Browse files Browse the repository at this point in the history
Feat: Add lo.BatchReverse
  • Loading branch information
muXxer authored Feb 23, 2024
2 parents 7c72785 + 8b1abc1 commit c117786
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lo/batch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lo

// Batch creates a new function that calls the given functions in order (nil entries are ignored).
func Batch(callbacks ...func()) func() {
return func() {
for _, callback := range callbacks {
Expand All @@ -9,3 +10,14 @@ func Batch(callbacks ...func()) func() {
}
}
}

// BatchReverse creates a new function that calls the given functions in reverse order (nil entries are ignored).
func BatchReverse(callbacks ...func()) func() {
return func() {
for i := len(callbacks) - 1; i >= 0; i-- {
if callback := callbacks[i]; callback != nil {
callback()
}
}
}
}

0 comments on commit c117786

Please sign in to comment.