You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mocking.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -641,6 +641,8 @@ Under test doubles, there are various types like stubs, spies and indeed mocks!
641
641
642
642
In Go 1.23 [iterators were introduced](https://tip.golang.org/doc/go1.23). We can use iterators in various ways, in this instance we can make a `countdownFrom` iterator, which will return the numbers to countdown in reverse order.
643
643
644
+
Before we get into how we write custom iterators, let's see how we use them. Rather than writing a fairly imperative looking loop to count down from a number, we can make this code look more expressive by `range`-ing over our custom `countdownFrom` iterator.
Before we get into how we write custom iterators, let's see how we use it. Rather than writing a fairly imperative looking loop to count down from a number, we can make this code look more expressive by `range`-ing over our custom `countdownFrom` iterator.
656
-
657
-
To write an iterator, a function that can be used in a `range` loop, you need to write a function in a particular way. From the docs:
657
+
To write an iterator like `countDownFrom`, you need to write a function in a particular way. From the docs:
658
658
659
659
The “range” clause in a “for-range” loop now accepts iterator functions of the following types
0 commit comments