If you are talking about a real application for iterators, I find it incredibly useful to do paged requests.
These requests are requests which only give a certain chunk of data corresponding to the page. Some API's also do not provide a way to see how many pages are there in total.
Example
asyncfunction*fetchTweet(){letpage=0;letresponse;while(true){response=awaitfetch('https://twitter.com/latest?page='+page++);if(response.length===0){break;}yieldresponse;}}asyncfunctiongetAllTweets(){for(constresultofawaitgetAllTweets()){// do something one by one with result}// handle all of them togetherconstallTweets=awaitPromise.all([...getAllTweets()]);}
What will be a real implementation for iterators?
If you are talking about a real application for iterators, I find it incredibly useful to do paged requests.
These requests are requests which only give a certain chunk of data corresponding to the page. Some API's also do not provide a way to see how many pages are there in total.
Example
I wrote a similar article on Iterators, feel free to check it out dev.to/kepta/how-i-learned-to-stop...