From fc479b4dcdfe682e028614c60c20420cbce35a62 Mon Sep 17 00:00:00 2001 From: gkdr Date: Sat, 22 Jan 2022 17:10:39 +0100 Subject: [PATCH 1/2] feat: tea.Batch() returns nil if all Cmds were nil --- tea.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tea.go b/tea.go index fdf29ee650..a5c6c1ec74 100644 --- a/tea.go +++ b/tea.go @@ -122,6 +122,17 @@ func Batch(cmds ...Cmd) Cmd { if len(cmds) == 0 { return nil } + + nilCount := 0 + for _, cmd := range cmds { + if cmd == nil { + nilCount++ + } + } + if nilCount == len(cmds) { + return nil + } + return func() Msg { return batchMsg(cmds) } From 6c421776cf46be24b63c576dc6c2bb73ef0d8773 Mon Sep 17 00:00:00 2001 From: gkdr Date: Sat, 22 Jan 2022 17:21:14 +0100 Subject: [PATCH 2/2] docs: specify behaviour in comment --- tea.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tea.go b/tea.go index a5c6c1ec74..f86187676f 100644 --- a/tea.go +++ b/tea.go @@ -111,6 +111,8 @@ type Program struct { // Batch performs a bunch of commands concurrently with no ordering guarantees // about the results. Use a Batch to return several commands. +// If the slice of commands has a length of 0 or only contains nil commands, +// the function itself returns nil. // // Example: //