from itertools import tee, zip_longest
from typing import Iterable


def pairs(iterable) -> Iterable:
    """
    Return successive pairs taken from the input iterable.

    Like :py:func:`itertools.pairwise` in 3.10, but will always include the last element by itself.

    Example:

            >>> list(pairs("ABCD"))
            [("A", "B"), ("B", "C"), ("C", "D"), ("D", None)]
            >>> list(pairs("ABC"))
            [("A", "B"), ("B", "C"), ("C", None)]

    Args:
        iterable: The iterable to combine into pairs.

    Returns:
        An iterable of pairs.
    """

    a, b = tee(iterable)
    next(b, None)
    return zip_longest(a, b)