1 00:00:01,280 --> 00:00:09,630 I traitors are state full objects meaning once we have consumed a value from them it's gone. 2 00:00:09,630 --> 00:00:20,090 The next function compute the next value in a sequence given the ITER raters current state and the. 3 00:00:20,090 --> 00:00:21,820 I did it as always. 4 00:00:21,820 --> 00:00:26,880 Keep track of how much of the stream has already been computed. 5 00:00:27,340 --> 00:00:39,260 Let us call the next function on the object the ITER data object will be June 1 because this is the 6 00:00:39,260 --> 00:00:42,840 first time the next function is being called on this object. 7 00:00:42,890 --> 00:00:48,620 It is going to write down the first value in the sequence which is 1. 8 00:00:48,830 --> 00:00:54,100 And also this is going to change the item it does state. 9 00:00:54,230 --> 00:01:03,720 If we then make a call to the next function again by passing the same object or b j 1 it is going to 10 00:01:03,750 --> 00:01:09,120 return the next value in the sequence which is 4. 11 00:01:09,840 --> 00:01:18,450 So the return value is different from the previously calculated value and also once the ITER data invokes 12 00:01:18,450 --> 00:01:24,560 the next method the calculated while you get consumed and thrown away. 13 00:01:24,810 --> 00:01:32,560 Changing the item does state so when you call the next method or the next function. 14 00:01:32,580 --> 00:01:39,840 Again it's going to write on the next numbered in the sequence. 15 00:01:40,230 --> 00:01:48,330 So instead of returning the first item that the next function is called the ideation resumes where it 16 00:01:48,330 --> 00:01:49,290 left off. 17 00:01:49,290 --> 00:01:59,040 Also remember we can only go forward in a sequence but we cannot go backwards and once a value has been 18 00:01:59,040 --> 00:02:06,660 consumed we cannot generate the value again in order to better understand this concept let's look at 19 00:02:06,660 --> 00:02:07,660 an example. 20 00:02:07,730 --> 00:02:08,280 Let us. 21 00:02:08,280 --> 00:02:08,840 I did it. 22 00:02:08,850 --> 00:02:12,190 All the elements of the list using the next function. 23 00:02:12,240 --> 00:02:20,890 So we need to first convert this list into a nitrate that object in order to iterate over the element 24 00:02:20,950 --> 00:02:22,840 using the next function. 25 00:02:22,870 --> 00:02:36,750 So let us call the I directed object as ITER 3 and then assign this to the value added on by these ITER 26 00:02:36,750 --> 00:02:42,080 function next boss list 1 as an argument. 27 00:02:43,000 --> 00:02:45,250 So here we have the. 28 00:02:45,250 --> 00:02:48,570 I did 3 I directed object. 29 00:02:49,210 --> 00:02:51,680 So this is a list I deleted. 30 00:02:51,880 --> 00:03:02,490 Now let us call the next function on this item dated rated object so the first value in this sequence 31 00:03:02,880 --> 00:03:04,980 has been generated. 32 00:03:06,360 --> 00:03:08,820 It does not call the next function. 33 00:03:08,820 --> 00:03:16,210 Again so the next real you in this sequence has been generated. 34 00:03:16,220 --> 00:03:27,830 Now I want to see if the values 5 and 10 still exist in the AI iterator object sequence or not. 35 00:03:28,370 --> 00:03:29,850 So how can we do that. 36 00:03:29,900 --> 00:03:36,560 Let us pass this idea data object to a list and see the contents of the list. 37 00:03:36,560 --> 00:03:39,150 So let's pass the AI traitor object. 38 00:03:39,230 --> 00:03:43,730 I D E R three to the list and execute. 39 00:03:43,730 --> 00:03:51,730 So as we can see the elements 5 and 10 have been consumed by the next function. 40 00:03:51,770 --> 00:03:57,320 So these values have been removed from the item data object sequence.