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

Pattern matching LazyList #11750

Open
charpov opened this issue Sep 26, 2019 · 1 comment

Comments

@charpov
Copy link

commented Sep 26, 2019

This is a feature request. With the switch from Stream to LazyList, I have lost the possibility of pattern matching on Empty. I find myself writing things like:

val LazyNil = LazyList.empty

def getAt[A](s: LazyList[A], i: Int): A = (s, i) match {
  case (LazyNil, _) => throw new NoSuchElementException("getAt(empty)")
  case (h #:: _, 0) => h
  case (_ #:: t, _) => getAt(t, i - 1)
}

Is there a good reason the empty_ value from LazyList is not public? If not, could it be changed into a public Empty at some point?

@SethTisue

This comment has been minimized.

Copy link
Member

commented Sep 26, 2019

thread: https://users.scala-lang.org/t/pattern-matching-lazylist/5105/3

(note that Discourse is a better place for this kind of thing, when it's still at the question stage)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.