diff --git a/take_last.go b/take_last.go index 89b7f55..7187400 100644 --- a/take_last.go +++ b/take_last.go @@ -111,14 +111,15 @@ func (it *takeLastWhileIterator[T]) build() { s := iteratorToSlice(it.it) if !it.whileFunc(s[len(s)-1]) { it.it = emptyIter[T]() - } else { - for i := len(s) - 2; i >= 0; i-- { - if !it.whileFunc(s[i]) { - s = s[i+1:] - break - } + it.built = true + return + } + for i := len(s) - 2; i >= 0; i-- { + if !it.whileFunc(s[i]) { + s = s[i+1:] + break } - it.it = makeSliceIterator(s) } + it.it = makeSliceIterator(s) it.built = true }