Is there a (cheap, i.e no list allocations) way to...
# announcements
d
Is there a (cheap, i.e no list allocations) way to get the size of a range? Like
(1..5).size
?
h
Copy code
val IntRange.size: Int
	get() = endInclusive - start + 1
I believe it's not in the stdlib because it wouldn't work for uncountable ranges.
d
Some ranges are countable though. Hmmph.
h
It's a bit weird: There's a special
ClosedFloatingPointRange
but no special for countable ranges (which, if it existed, would be a great place for that size property)
i
Also note that some ranges like
Int.MIN_VALUE..Int.MAX_VALUE
cannot have their
size
expressed as
Int
.
d
Pesky. But I get it.