Grokking Advanced Go
0% completed
Pull Iterators
Two warehouses each produce a stream of orders sorted by ID, and a report needs one stream sorted by ID. How can a single loop take the smaller of two values when each value is inside a different iterator?
A range loop cannot express this without first copying a stream into a slice. The iterator controls the loop: it runs, and it calls the loop body whenever it has a value. A loop body over the first stream can start a range over the second stream, but it must end that inner loop before the first stream can send its next value
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%