-
Notifications
You must be signed in to change notification settings - Fork 21
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
LazyList.from(1) match { case LazyList(x, xs @ _*) => xs }
never terminates
#11687
Comments
https://github.com/scala/scala/blob/2.13.x/test/files/run/matchonstream.scala should have caught this but didn't because the binding for |
@szeiger I assigned this to the 2.13.1 milestone since it seems pretty critical to me, but it might be too late for that already. |
it's not clear to me that
It's also possible that the problem is |
I think that the current behavior is correct, calling toSeq on a View does evaluate the view. The toSeq operation is a noop only on Seq subtypes, which is not the case of SeqView. |
I agree with Julien (and with Nth's "it's not clear to me that..."). In the 2.13 design, going to a view doesn't preserve exact type information of the input collection; a |
So why isn't a view of the LazyList just the LazyList itself? |
because in the new design views aren't collections and collections aren't views views are just reusable iterators I'm not sure I understand your thinking here, but it sounds to me like you're still thinking in terms of what 2.8-12 views were. but the 2.13 views are something else, something new, that you should approach with fresh expectations. a different design solution that addresses some of the same problems |
If you think about it a little differently, a |
But are there any intentional semantic differences between a LazyList and a view of a LazyList? |
The new behavior of |
how about the |
@SethTisue I believe scala/scala#8340 should fix that |
LazyList.from(1).view.toSeq
never terminates, which means LazyList.from(1) match { case LazyList(x, xs @ _*) => xs }
never does eitherLazyList.from(1) match { case LazyList(x, xs @ _*) => xs }
never terminates
@smarter I’m curious to know the motivation for using a view over a lazy list (or a Stream in 2.12) |
I imagine the motivation is to do something lazily on any kind of collection, this is what UnapplySeqWrapper was trying to do, except it doesn't behave as one might expect on lazy collections. |
I think the purpose of |
Indeed, we could just simplify the signature and make |
Yes, I think this this can be fixed. Making it elegant and/or binary compatible might be a problem but in principle I see no reason why |
Same for
Stream.from(1).view.toSeq
which did terminate in 2.12. The behavior on unapply arises because we go through UnapplySeqWrapper#drop: https://github.com/scala/scala/blob/f23f96c36a3cc0a44a60d28bac0200873686c410/src/library/scala/collection/Factory.scala#L315/cc @NthPortal, the definitive expert on LazyList :).
The text was updated successfully, but these errors were encountered: