Thread
#stdlib
    h

    holgerbrandl

    1 year ago
    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.
    Milan Hruban

    Milan Hruban

    1 year ago
    there is
    val numbers = List(10) { it * 2 }
    that's nice enough for me
    e

    ephemient

    1 year ago
    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

    holgerbrandl

    1 year ago
    @Milan Hruban Great solution. Thanks!
    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.
    louiscad

    louiscad

    1 year ago
    This file was deleted 😔