-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix LazyList.range [ci: last-only]
#10767
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
base: 2.13.x
Are you sure you want to change the base?
Changes from 1 commit
6de2bf8
91088b5
bd3db0d
f7745a4
2028dae
fbc2623
1ac4f64
b4eb90a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -968,17 +968,6 @@ final class LazyList[+A] private(private[this] var lazyState: () => LazyList.Sta | |
| */ | ||
| @SerialVersionUID(3L) | ||
| object LazyList extends SeqFactory[LazyList] { | ||
| // Override SeqFactory methods. | ||
| override def range[A: Integral](start: A, end: A): LazyList[A] = | ||
| range(start, end, step = Integral[A].one) | ||
|
|
||
| override def range[A](start: A, end: A, step: A)(implicit ev: Integral[A]): LazyList[A] = | ||
| newLL(rangeImpl(start, end, step)) | ||
|
|
||
| private[this] def rangeImpl[A](start: A, end: A, step: A)(implicit ev: Integral[A]): State[A] = | ||
| if (ev.lt(start, end)) sCons(start, newLL(rangeImpl(ev.plus(start, step), end, step))) | ||
| else State.Empty | ||
|
|
||
| // Eagerly evaluate cached empty instance | ||
| private[this] val _empty = newLL(State.Empty).force | ||
|
|
||
|
|
@@ -1241,6 +1230,16 @@ object LazyList extends SeqFactory[LazyList] { | |
| at(0) | ||
| } | ||
|
|
||
| override def range[A: Integral](start: A, end: A): LazyList[A] = | ||
| range(start, end, step = Integral[A].one) | ||
|
|
||
| override def range[A](start: A, end: A, step: A)(implicit ev: Integral[A]): LazyList[A] = | ||
| newLL(rangeImpl(start, end, step)) | ||
|
BalmungSan marked this conversation as resolved.
Outdated
|
||
|
|
||
| private[this] def rangeImpl[A](start: A, end: A, step: A)(implicit ev: Integral[A]): State[A] = | ||
| if (ev.lt(start, end)) sCons(start, newLL(rangeImpl(ev.plus(start, step), end, step))) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm, wait, this does not allow reversed ranges, does it? Like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this made me think. This could be a good way to test this without a CPU trap. We just request the reversed range and then we can indeed ask for the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, the check is incorrect, hmm. probably need to check the sign or something as well. I'll have another look shortly
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my thought is to check the sign of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed an implementation that allows for reverse |
||
| else State.Empty | ||
|
|
||
| // significantly simpler than the iterator returned by Iterator.unfold | ||
| override def unfold[A, S](init: S)(f: S => Option[(A, S)]): LazyList[A] = | ||
| newLL { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.