@@ -22,15 +22,21 @@ class TapEverySuite extends AnyFunSpec with Matchers:
2222 Iterator .from(0 ).tapEvery(1 )((_, id) => seen += id).take(3 ).toList
2323 seen.toList shouldBe List (1 , 2 )
2424
25- describe(" LazyList.tapEvery " ):
25+ describe(" Iterator.after " ):
2626
27- it(" fires at every n-th index but not at zero" ):
28- val seen = ListBuffer .empty[(String , Int )]
29- LazyList .from(0 ).map(i => s " e $i" ).tapEvery(3 )((t, id) => seen += ((t, id))).take(10 ).toList
30- seen.toList shouldBe List ((" e3" , 3 ), (" e6" , 6 ), (" e9" , 9 ))
27+ it(" counts from zero, so the first element is the state after no steps" ):
28+ Iterator .from(0 ).after(0 ) shouldBe 0
3129
32- it(" stays lazy until the elements are forced" ):
33- val seen = ListBuffer .empty[Int ]
34- val tapped = LazyList .from(0 ).tapEvery(1 )((_, id) => seen += id)
35- seen.toList shouldBe empty
36- tapped.take(3 ).toList shouldBe List (0 , 1 , 2 )
30+ it(" returns the element that many steps in" ):
31+ Iterator .from(0 ).after(3 ) shouldBe 3
32+
33+ it(" advances the iterator past what it returns" ):
34+ val trajectory = Iterator .from(0 )
35+ trajectory.after(3 ) shouldBe 3
36+ trajectory.next() shouldBe 4
37+
38+ it(" throws when the iterator ends first" ):
39+ a[NoSuchElementException ] should be thrownBy Iterator (0 , 1 ).after(5 )
40+
41+ it(" rejects a negative number of steps" ):
42+ an[IllegalArgumentException ] should be thrownBy Iterator .from(0 ).after(- 1 )
0 commit comments