It appears we lack a combinator to create IndexedSeq[A] backed by a size and a user-supplied function Int => A, eg
def fromFunction[A](n: Int, f: Int => A) = new IndexedSeq[A] {
def length = n
def apply(i: Int): A = f(i)
}
The difference to the existing tabulate is that tabulate will eagerly invoke the function at creation time, whereas the above impl will invoke f when needed.
It appears we lack a combinator to create
IndexedSeq[A]
backed by a size and a user-supplied functionInt => A
, egThe difference to the existing
tabulate
is that tabulate will eagerly invoke the function at creation time, whereas the above impl will invokef
when needed.