def ibatch(size, iterable=None, rest=False):
@iterflow<EOL>def exact_size(it):<EOL><INDENT>it = iter(it)<EOL>while True:<EOL><INDENT>yield [it.next() for _ in xrange(size)]<EOL><DEDENT><DEDENT>@iterflow<EOL>def at_most(it):<EOL><INDENT>it = iter(it)<EOL>while True:<EOL><INDENT>data = []<EOL>for _ in xrange(size):<EOL><INDENT>try:<EOL><INDENT>data.append(it.next())<EOL><DEDENT>except StopIteration:<EOL><INDENT>if data:<EOL><INDENT>yield data<EOL><DEDENT>raise StopIteration<EOL><DEDENT><DEDENT>yield data<EOL><DEDENT><DEDENT>ibatchit = at_most if rest else exact_size<EOL>return ibatchit if iterable is None else ibatchit(iterable)<EOL>
add example
:param size:
:param iterable:
:param rest:
:return: