Skip to content

Commit

Permalink
fixup! #21 Add TakeLastWhile implements
Browse files Browse the repository at this point in the history
  • Loading branch information
meian committed Feb 5, 2022
1 parent 1a71430 commit aa9e3af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions take_last.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion take_last_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})
}
Expand Down

0 comments on commit aa9e3af

Please sign in to comment.