@@ -715,6 +715,20 @@ class LazyListLazinessTest {
715
715
// assertLazyAllSkipping(op, 4)
716
716
// }
717
717
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
+
718
732
/* factory laziness tests */
719
733
720
734
@ Test
@@ -776,14 +790,12 @@ class LazyListLazinessTest {
776
790
assertRepeatedlyLazy(factory)
777
791
}
778
792
779
- @ Test
780
- def `#:: properlyLazy` (): Unit = {
793
+ private def genericCons_properlyLazy (cons : (=> Int , => LazyList [Int ]) => LazyList [Int ]): Unit = {
781
794
val headInitFactory = lazyListFactory { init =>
782
795
def gen (index : Int ): LazyList [Int ] = {
783
796
def elem (): Int = { init.evaluate(index); index }
784
797
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 ))
787
799
}
788
800
789
801
gen(0 )
@@ -795,7 +807,7 @@ class LazyListLazinessTest {
795
807
if (index >= LazinessChecker .count) LazyList .empty
796
808
else {
797
809
init.evaluate(index)
798
- index #:: gen(index + 1 )
810
+ cons( index, gen(index + 1 ) )
799
811
}
800
812
}
801
813
@@ -804,6 +816,16 @@ class LazyListLazinessTest {
804
816
assertRepeatedlyLazy(tailInitFactory)
805
817
}
806
818
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
+
807
829
@ Test
808
830
def `#::: properlyLazy` (): Unit = {
809
831
val headInitFactory = lazyListFactory { init =>
0 commit comments