def overlap(r1, r2, construct=range):
    """
    Overlap of two ranges.

    For two ranges *r1* and *r2* return the normalized range corresponding to
    the intersection ot the sets (of consecutive integers) corresponding to
    *r1* and *r2*

    Return a normalized result, which is either None, or an object constructed
    using *construct*.
    """
    if r1 is None or r1.stop <= r1.start:
        return None
    if r2 is None or r2.stop <= r2.start:
        return None
    if r1.stop <= r2.start or r2.stop <= r1.start:
        return None
    return construct(max(r1.start, r2.start), min(r1.stop, r2.stop))