๐ฐiterator
object that can produce the next iteration result.
has next() method that returns an iteration result. (similar to iterator objects conforming to IteratorProtocol in Swift)
iterators only iterate onceโ๏ธ
iterators๏ผ
str.matchAll() - returns an iterator of matching results.
objects returned by generator functions.
iterators don't always run all the way to the end๏ผ
a for-of loop might be terminated with a break, return, or an exception.
when destructuring an iterable, the next() method (of an iterator) is only called enough times to obtain values for each variable.
All iterator protocol methods
return() - give iterator a chance to do "cleanup" actions.
throw()
are expected to return an iteration result object.
Last updated
Was this helpful?