# Path: rash/utils/py3compat.py
# PY3 = (sys.version_info[0] >= 3)
#     def nested(*managers):


import itertools
from .py3compat import zip
    """
    (it0, it1) = itertools.tee(iterative)
    ps = _backward_shifted_predicate(predicate, num, it1)
    return (e for (e, p) in zip(it0, ps) if p)


def include_after(predicate, num, iterative):
    """
    Return elements in `iterative` including `num`-after elements.

    >>> list(include_after(lambda x: x == 'b', 2, 'abcbcde'))
    ['b', 'c', 'b', 'c', 'd']

    """
    (it0, it1) = itertools.tee(iterative)
    ps = _forward_shifted_predicate(predicate, num, it1)
    return (e for (e, p) in zip(it0, ps) if p)


def include_context(predicate, num, iterative):
    """
    Return elements in `iterative` including `num` before and after elements.

    >>> ''.join(include_context(lambda x: x == '!', 2, 'bb!aa__bb!aa'))
    'bb!aabb!aa'

    """
    (it0, it1, it2) = itertools.tee(iterative, 3)
    psf = _forward_shifted_predicate(predicate, num, it1)
    psb = _backward_shifted_predicate(predicate, num, it2)

# Path: rash/utils/py3compat.py
# PY3 = (sys.version_info[0] >= 3)
#     def nested(*managers):


# Path: rash/utils/iterutils.py
import itertools
from .py3compat import zip

    """
    (it0, it1) = itertools.tee(iterative)
    ps = _backward_shifted_predicate(predicate, num, it1)
    return (e for (e, p) in zip(it0, ps) if p)


def include_after(predicate, num, iterative):
    """
    Return elements in `iterative` including `num`-after elements.

    >>> list(include_after(lambda x: x == 'b', 2, 'abcbcde'))
    ['b', 'c', 'b', 'c', 'd']

    """
    (it0, it1) = itertools.tee(iterative)
    ps = _forward_shifted_predicate(predicate, num, it1)
    return (e for (e, p) in zip(it0, ps) if p)


def include_context(predicate, num, iterative):
    """
    Return elements in `iterative` including `num` before and after elements.

    >>> ''.join(include_context(lambda x: x == '!', 2, 'bb!aa__bb!aa'))
    'bb!aabb!aa'

    """
    (it0, it1, it2) = itertools.tee(iterative, 3)
    psf = _forward_shifted_predicate(predicate, num, it1)
    psb = _backward_shifted_predicate(predicate, num, it2)

    return (e for (e, pf, pb) in zip(it0, psf, psb) if pf or pb)