Surprised there is no intersect for the Range. Pro...
# stdlib
e
Surprised there is no intersect for the Range. Probably because there is case when no intersection is found. But would go probably for intersectOrNull
e
Copy code
fun IntRange.intersect(other: IntRange): IntRange =
    maxOf(this.first, other.first)..minOf(this.last, other.last)
may result in an empty range but that's probably better than
null
e
I thought that it will throw exception in case of first above last
e
nope
e
Oke, cool
e
(1..0).isEmpty()
=>
true
j
@ephemient how does that work for ranges with negative step?
e
steps are in e.g. IntProgression not Range
j
Ah, good point. It seems I haven't played enough with these things 😄