From 763564c4e23cf43b67093a8367493b3486da1a3f Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Fri, 4 Feb 2022 23:09:59 +0900 Subject: [PATCH] fixup! #21 Add TakeLastWhile implements --- take_last.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 }