Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combinator to create IndexedSeq backed by a size and a user-supplied function #103

Open
benhutchison opened this issue Nov 25, 2021 · 0 comments

Comments

@benhutchison
Copy link

benhutchison commented Nov 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant