ref: 0e75af74db30259ec355a7b79a1e257d5fe00eef
parent: 5f1aafafb40299bb4c8aebf71e05843431eb84c5
author: Baibhav Vatsa <[email protected]>
date: Fri Oct 11 09:15:39 EDT 2019
tpl: Last now accepts 0 as limit Modified the if conditional because of which last threw an error if 0 was passed as limit. The function now returns an empty slice if it is called with 0 as limit. The behavior of first and last is now the same when 0 is passed as limit. Also added tests to test the new behavior. Fixes #6419
--- a/tpl/collections/collections.go
+++ b/tpl/collections/collections.go
@@ -378,7 +378,7 @@
return nil, err
}
- if limitv < 1 {
+ if limitv < 0 {
return nil, errors.New("can't return negative/empty count of items from sequence")
}
--- a/tpl/collections/collections_test.go
+++ b/tpl/collections/collections_test.go
@@ -495,6 +495,8 @@
{int64(2), []int{100, 200, 300}, []int{200, 300}},
{100, []int{100, 200}, []int{100, 200}},
{"1", []int{100, 200, 300}, []int{300}},
+ {"0", []int{100, 200, 300}, []int{}},
+ {"0", []string{"a", "b", "c"}, []string{}},
// errors
{int64(-1), []int{100, 200, 300}, false},
{"noint", []int{100, 200, 300}, false},