scala-library-next
scala-library-next copied to clipboard
Combinator to create IndexedSeq backed by a size and a user-supplied function
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.