From cae07ce84b3bd4a33fd18b5109a1a3c3dce2191c Mon Sep 17 00:00:00 2001 From: Ricardo N Feliciano Date: Sat, 22 Sep 2018 14:58:46 -0400 Subject: tpl/collections: Allow first function to return an empty slice Fixes #5235 --- tpl/collections/collections.go | 4 ++-- tpl/collections/collections_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'tpl/collections') diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 4400a26b2..491421631 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -215,8 +215,8 @@ func (ns *Namespace) First(limit interface{}, seq interface{}) (interface{}, err return nil, err } - if limitv < 1 { - return nil, errors.New("can't return negative/empty count of items from sequence") + if limitv < 0 { + return nil, errors.New("can't return negative count of items from sequence") } seqv := reflect.ValueOf(seq) diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index c2d4cacbf..7b15151d2 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -256,6 +256,7 @@ func TestFirst(t *testing.T) { {int64(2), []int{100, 200, 300}, []int{100, 200}}, {100, []int{100, 200}, []int{100, 200}}, {"1", []int{100, 200, 300}, []int{100}}, + {0, []string{"h", "u", "g", "o"}, []string{}}, {int64(-1), []int{100, 200, 300}, false}, {"noint", []int{100, 200, 300}, false}, {1, nil, false}, -- cgit v1.2.3