I traitors are state full objects meaning once we have consumed a value from them it's gone.
The next function compute the next value in a sequence given the ITER raters current state and the.
I did it as always.
Keep track of how much of the stream has already been computed.
Let us call the next function on the object the ITER data object will be June 1 because this is the
first time the next function is being called on this object.
It is going to write down the first value in the sequence which is 1.
And also this is going to change the item it does state.
If we then make a call to the next function again by passing the same object or b j 1 it is going to
return the next value in the sequence which is 4.
So the return value is different from the previously calculated value and also once the ITER data invokes
the next method the calculated while you get consumed and thrown away.
Changing the item does state so when you call the next method or the next function.
Again it's going to write on the next numbered in the sequence.
So instead of returning the first item that the next function is called the ideation resumes where it
left off.
Also remember we can only go forward in a sequence but we cannot go backwards and once a value has been
consumed we cannot generate the value again in order to better understand this concept let's look at
an example.
Let us.
I did it.
All the elements of the list using the next function.
So we need to first convert this list into a nitrate that object in order to iterate over the element
using the next function.
So let us call the I directed object as ITER 3 and then assign this to the value added on by these ITER
function next boss list 1 as an argument.
So here we have the.
I did 3 I directed object.
So this is a list I deleted.
Now let us call the next function on this item dated rated object so the first value in this sequence
has been generated.
It does not call the next function.
Again so the next real you in this sequence has been generated.
Now I want to see if the values 5 and 10 still exist in the AI iterator object sequence or not.
So how can we do that.
Let us pass this idea data object to a list and see the contents of the list.
So let's pass the AI traitor object.
I D E R three to the list and execute.
So as we can see the elements 5 and 10 have been consumed by the next function.
So these values have been removed from the item data object sequence.