Skip to content

Commit

Permalink
Catch StopIteration errors for Python 3.7 compatibility (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrink10 authored and EntilZha committed Sep 30, 2018
1 parent 7a64bc5 commit 1feedea
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions functional/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,12 @@ def grouped_impl(wrap, size, sequence):
:return: grouped sequence
"""
iterator = iter(sequence)
while True:
batch = islice(iterator, size)
yield list(chain((wrap(next(batch)),), batch))
try:
while True:
batch = islice(iterator, size)
yield list(chain((wrap(next(batch)),), batch))
except StopIteration:
return


def grouped_t(wrap, size):
Expand Down

0 comments on commit 1feedea

Please sign in to comment.