feat: tea.Batch returns nil if all cmds are nil (#217)

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2022-02-03 12:08:34 -03:00
committed by GitHub
parent a09e0e80cb
commit 9a06319ff1
2 changed files with 34 additions and 2 deletions

11
tea.go
View File

@@ -119,11 +119,18 @@ type Program struct {
// }
//
func Batch(cmds ...Cmd) Cmd {
if len(cmds) == 0 {
var validCmds []Cmd
for _, c := range cmds {
if c == nil {
continue
}
validCmds = append(validCmds, c)
}
if len(validCmds) == 0 {
return nil
}
return func() Msg {
return batchMsg(cmds)
return batchMsg(validCmds)
}
}