Skip to content

Commit eedae26

Browse files
committed
comment the implementation
1 parent 11cd3d0 commit eedae26

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/scala/scala/collection/immutable/next/package.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ package object next {
2121
* The result is a true cycle occupying only constant memory.
2222
*/
2323
def cycle: LazyList[T] =
24+
// case 1: the input is already known to be empty
25+
// (the test can be changed to ll.knownIsEmpty when this code moves to stdlib)
2426
if (ll.knownSize == 0) LazyList.empty
27+
// we don't want to force the input's empty-or-not status until we must.
28+
// `LazyList.empty #:::` accomplishes that delay
2529
else LazyList.empty #::: {
30+
// case 2: the input is later discovered to be empty
31+
// (distinguishing this from case 3 isn't necessary for correctness, but we
32+
// might as well avoid the lazy val path if we can)
2633
if (ll.isEmpty) LazyList.empty
2734
else {
35+
// case 3: non-empty
2836
lazy val result: LazyList[T] = ll #::: result
2937
result
3038
}

0 commit comments

Comments
 (0)