@@ -715,6 +715,20 @@ class LazyListLazinessTest {
715715 // assertLazyAllSkipping(op, 4)
716716 // }
717717
718+ private def genericCons_unapply_properlyLazy (unapply : LazyList [Int ] => Option [(Int , LazyList [Int ])]): Unit = {
719+ assertLazyAllSkipping(unapply, 1 )
720+ }
721+
722+ @ Test
723+ def cons_unapply_properlyLazy (): Unit = {
724+ genericCons_unapply_properlyLazy(LazyList .cons.unapply)
725+ }
726+
727+ @ Test
728+ def `#::_unapply_properlyLazy` (): Unit = {
729+ genericCons_unapply_properlyLazy(LazyList .#:: .unapply)
730+ }
731+
718732 /* factory laziness tests */
719733
720734 @ Test
@@ -776,14 +790,12 @@ class LazyListLazinessTest {
776790 assertRepeatedlyLazy(factory)
777791 }
778792
779- @ Test
780- def `#:: properlyLazy` (): Unit = {
793+ private def genericCons_properlyLazy (cons : (=> Int , => LazyList [Int ]) => LazyList [Int ]): Unit = {
781794 val headInitFactory = lazyListFactory { init =>
782795 def gen (index : Int ): LazyList [Int ] = {
783796 def elem (): Int = { init.evaluate(index); index }
784797 if (index >= LazinessChecker .count) LazyList .empty
785- // else elem() #:: gen(index + 1)
786- else gen(index + 1 ).#:: (elem())
798+ else cons(elem(), gen(index + 1 ))
787799 }
788800
789801 gen(0 )
@@ -795,7 +807,7 @@ class LazyListLazinessTest {
795807 if (index >= LazinessChecker .count) LazyList .empty
796808 else {
797809 init.evaluate(index)
798- index #:: gen(index + 1 )
810+ cons( index, gen(index + 1 ) )
799811 }
800812 }
801813
@@ -804,6 +816,16 @@ class LazyListLazinessTest {
804816 assertRepeatedlyLazy(tailInitFactory)
805817 }
806818
819+ @ Test
820+ def cons_properlyLazy (): Unit = {
821+ genericCons_properlyLazy(LazyList .cons(_, _))
822+ }
823+
824+ @ Test
825+ def `#::_properlyLazy` (): Unit = {
826+ genericCons_properlyLazy(_ #:: _)
827+ }
828+
807829 @ Test
808830 def `#::: properlyLazy` (): Unit = {
809831 val headInitFactory = lazyListFactory { init =>
0 commit comments