`IntRange.forEach` uses `Iterable.forEach`, so `(1...
# stdlib
d
IntRange.forEach
uses
Iterable.forEach
, so
(1..n).forEach { ... }
creates an
Iterator
, while
for (k in (1..n)) { ... }
is optimized to use a while-loop, not even creating the original
IntRange
object. Could
IntRange
receive its own
forEach
extension method to preserve this optimization, and perhaps receive additional optimizations for common methods like
map
?
r
Those are a little different. The for loop optimization is a compiler intrinsic, not a library function. Not that it invalidates your request, just that I don't think the two are very related.
i
d
@Ruckus it's a compiler intrinsic that a specialized inline function would be able to take advantage of, unlike an
Iterable
extension function.