diff --git a/take_last.go b/take_last.go index 7187400..f1eaa87 100644 --- a/take_last.go +++ b/take_last.go @@ -109,6 +109,11 @@ func (it *takeLastWhileIterator[T]) Current() T { func (it *takeLastWhileIterator[T]) build() { s := iteratorToSlice(it.it) + if len(s) == 0 { + it.it = emptyIter[T]() + it.built = true + return + } if !it.whileFunc(s[len(s)-1]) { it.it = emptyIter[T]() it.built = true diff --git a/take_last_test.go b/take_last_test.go index 679e6c6..38f6c6c 100644 --- a/take_last_test.go +++ b/take_last_test.go @@ -187,7 +187,7 @@ func TestTakeLastWhile(t *testing.T) { itb = gcf.TakeLastWhile(itb, func(v int) bool { return v > 2 }) testBeforeAndAfter(t, itb) - testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + testEmpties(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { return gcf.TakeLastWhile(itb, func(v int) bool { return true }) }) }