Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better LazyList.range impl
Co-authored-by: Marissa | April <[email protected]>
  • Loading branch information
BalmungSan and NthPortal authored Apr 30, 2024
commit bd3db0d40a434241d674e5ea0d23ab6f19f5248f
6 changes: 5 additions & 1 deletion src/library/scala/collection/immutable/LazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,11 @@ object LazyList extends SeqFactory[LazyList] {
range(start, end, step = Integral[A].one)

override def range[A](start: A, end: A, step: A)(implicit ev: Integral[A]): LazyList[A] =
LazyList.iterate(start)(ev.plus(_, step)).takeWhile(ev.lt(_, end))
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
Expand Down