Skip to content

Commit 5af8552

Browse files
authored
Merge pull request scala/scala#7000 from NthPortal/topic/lazyList/PR
Make LazyList fully lazy
2 parents fc6e1b7 + 45a385b commit 5af8552

File tree

3 files changed

+886
-496
lines changed

3 files changed

+886
-496
lines changed

library/src/scala/collection/LinearSeq.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,6 @@ trait LinearSeqOps[+A, +CC[X] <: LinearSeq[X], +C <: LinearSeq[A] with LinearSeq
5050

5151
override def isDefinedAt(x: Int): Boolean = x >= 0 && lengthCompare(x) > 0
5252

53-
// Optimized version of `drop` that avoids copying
54-
override def drop(n: Int): C = {
55-
@tailrec def loop(n: Int, s: C): C =
56-
if (n <= 0 || s.isEmpty) s
57-
else loop(n - 1, s.tail)
58-
loop(n, coll)
59-
}
60-
61-
override def dropWhile(p: A => Boolean): C = {
62-
@tailrec def loop(s: C): C =
63-
if (s.nonEmpty && p(s.head)) loop(s.tail)
64-
else s
65-
loop(coll)
66-
}
67-
6853
// `apply` is defined in terms of `drop`, which is in turn defined in
6954
// terms of `tail`.
7055
@throws[IndexOutOfBoundsException]
@@ -184,6 +169,21 @@ trait StrictOptimizedLinearSeqOps[+A, +CC[X] <: LinearSeq[X], +C <: LinearSeq[A]
184169
def hasNext = !current.isEmpty
185170
def next() = { val r = current.head; current = current.tail; r }
186171
}
172+
173+
// Optimized version of `drop` that avoids copying
174+
override def drop(n: Int): C = {
175+
@tailrec def loop(n: Int, s: C): C =
176+
if (n <= 0 || s.isEmpty) s
177+
else loop(n - 1, s.tail)
178+
loop(n, coll)
179+
}
180+
181+
override def dropWhile(p: A => Boolean): C = {
182+
@tailrec def loop(s: C): C =
183+
if (s.nonEmpty && p(s.head)) loop(s.tail)
184+
else s
185+
loop(coll)
186+
}
187187
}
188188

189189
/** A specialized Iterator for LinearSeqs that is lazy enough for Stream and LazyList. This is accomplished by not

0 commit comments

Comments
 (0)