# Path: infi/pyutils/python_compat.py
# _PYTHON_VERSION = platform.python_version()
# _IS_PYTHON_3 = _PYTHON_VERSION >= '3'
# _IS_BELOW_PYTHON_2_7 = _PYTHON_VERSION < '2.7'
# def get_underlying_function(f):
# def _get_underlying_classmethod_function(f):
#     def create_bound_method(func, self):
#     class TemporaryClass(object):


import itertools
from .python_compat import xrange

_NOTHING = object()

def iterate(collection):
    iterator = enumerate(itertools.chain(iter(collection), [_NOTHING]))
    prefetched = _NOTHING

    while True:
        index, element = next(iterator) if prefetched is _NOTHING else prefetched
        if element is _NOTHING:
            break
        prefetched = next(iterator)
        yield Iteration(
            counter0 = index,
            counter1 = index + 1,
            first = (index == 0),
            last  = prefetched[1] is _NOTHING
            ), element

class Iteration(object):

# Path: infi/pyutils/python_compat.py
# _PYTHON_VERSION = platform.python_version()
# _IS_PYTHON_3 = _PYTHON_VERSION >= '3'
# _IS_BELOW_PYTHON_2_7 = _PYTHON_VERSION < '2.7'
# def get_underlying_function(f):
# def _get_underlying_classmethod_function(f):
#     def create_bound_method(func, self):
#     class TemporaryClass(object):


# Path: infi/pyutils/iteration.py
import itertools
from .python_compat import xrange


_NOTHING = object()

def iterate(collection):
    iterator = enumerate(itertools.chain(iter(collection), [_NOTHING]))
    prefetched = _NOTHING

    while True:
        index, element = next(iterator) if prefetched is _NOTHING else prefetched
        if element is _NOTHING:
            break
        prefetched = next(iterator)
        yield Iteration(
            counter0 = index,
            counter1 = index + 1,
            first = (index == 0),
            last  = prefetched[1] is _NOTHING
            ), element

class Iteration(object):

    def __init__(self, counter0, counter1, first, last):