Is there an alternative for `repeat` that allows t...
# stdlib
h
Is there an alternative for
repeat
that allows to assign the result:
val created = repeat(n){ create_something()}
? Doing
(1..n).map{ create_something() }
does not feel elegant. I can certainly create it myself with
fun <T> repeat(n:Int, builder: (Int) -> T) = (1..n).map{ builder(it)}
but I wonder why it's not part of stdlib? It also does not really work well, because somehow it's not resolved when being placed in some other source file that is different from that which contains the call site.
m
there is
val numbers = List(10) { it * 2 }
that's nice enough for me
👍 1
👍🏻 2
e
somehow it's not resolved when being placed in some other source file
are they in the same package? otherwise it needs to be imported
h
@Milan Hruban Great solution. Thanks!
👋 1
Yeah, I just figured that out. Thanks @ephemient
And, indeed somehow the import was missing. I was relying on the IDE but somehow it missed it initially.
l
This file was deleted 😔