public Optional<Range<T>> intersect(Range<T> other) {
        if (overlaps(other))
            return Optional.of(new Range<>(
                v1 == null
                    ? other.v1
                    : other.v1 == null
                    ? v1
                    : v1.compareTo(other.v1) >= 0
                    ? v1
                    : other.v1,
                v2 == null
                    ? other.v2
                    : other.v2 == null
                    ? v2
                    : v2.compareTo(other.v2) <= 0
                    ? v2
                    : other.v2
            ));
        else
            return Optional.empty();
    }
The intersection of two ranges.
<p>
<pre><code>
// (2, 3)
range(1, 3).intersect(range(2, 4))

// none
range(1, 3).intersect(range(5, 8))
</code></pre>
jOOL/src/main/java/org/jooq/lambda/tuple/Range.java