-
Notifications
You must be signed in to change notification settings - Fork 21
LazyList
's last
method (and perhaps others?) should be lazier
#11089
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
Comments
as @szeiger indicates, there is a fundamental mismatch between the semantics of |
Those were the first methods I thought to try, so probably it's safe to say there are more examples. scala> def ll = (1 to 10).foldRight(LazyList[Int]())((x, xs) => (try x finally println(x)) #:: xs)
ll: scala.collection.immutable.LazyList[Int]
scala> ll.length
res3: Int = 10
scala> LazyList.fill(3)(try 1 finally println(1)).length
1
1
1
res4: Int = 3 |
LazyList#last
should be lazierLazyList#last
, length
(and others?) should be lazier
LazyList#last
, length
(and others?) should be lazierLazyList#last
should be lazier
LazyList#last
should be lazierLazyList
's last
and length
methods, and probably others, should be lazier
Maybe the head of
|
@sjrd I had the impression that a non-lazy head is the entire reason for this class's existence. With an eager head, isn't it Stream? |
No. The biggest difference between my alternative proposal and I strongly believe that the years-old complaint about See also scala/collection-strawman#367 |
@sjrd I always thought the way to deal with this was to propagate what is known about the size, as seen here. But I suppose that's neither here nor there. /** The Size hierarchy is:
* Size
* / \
* Atomic Bounded
* / \
* Infinite Precise
*
* Precise implies the exact size is known. Infinite means it's infinite.
* Bounded is a size lower bound and a (possibly infinite) atomic upper bound.
* Size forms a partial order, with some liberties taken at present.
* Operations on sizes which are ill-defined will result in "Unknown", which
* encodes no available size information: Bounded(Zero, Infinite).
*
* Invariants:
* - Precise is non-negative
*/ |
Hum ... I'm not sure how that is relevant, except that:
|
It's relevant because... never mind, it's irrelevant. |
for tracking purposes, can people add a list of methods that need more laziness to the description? |
@SethTisue |
LazyList
's last
and length
methods, and probably others, should be lazierLazyList
's last
method (and perhaps others?) should be lazier
@NthPortal okay I changed the ticket name again :-) |
There are other methods that got missed that aren't sufficiently lazy. I am in the middle of fixing them, and will try to add them to the description soon. If you find any other methods, please add them to the description as well or drop a comment. |
Tentatively leaving #11083 closed for now, but that may end up getting reopened as well. |
Note: this may be reverted by #11307 |
reported by @paulp at https://twitter.com/contrarivariant/status/1030065587559362561
are there other methods that may have this problem?
related: #11083
/cc @NthPortal @szeiger @julienrf
methods to fix:
last
dropRight
takeRight
slice
The text was updated successfully, but these errors were encountered: