Iterator ਪ্ਰੈਟਰਨ ਇਸ ਤਰੀਕੇ ਨੂੰ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ ਕਿ ਇੱਕ collection ਨੂੰ ਕ੍ਰਮ ਵਿੱਚ traverse ਕੀਤਾ ਜਾਵੇ ਜਦੋਂ ਕਿ ਇਸਦੀ ਅੰਦਰੂਨੀ ਬਣਤਰ ਨੂੰ ਸਾਹਮਣੇ ਨਾ ਰੱਖਿਆ ਜਾਵੇ। ਇਹ ਬਿਲਕੁਲ ਮੌਲਿਕ ਹੈ ਕਿ ਇਹ ਜ਼ਿਆਦਾਤਰ ਆਧੁਨਿਕ ਭਾਸ਼ਾਵਾਂ ਵਿੱਚ ਨਿਰਮਿਤ ਹੈ (for-of loops, iterators, generators)।
Iterator ਪ੍ਰੈਟਰਨ ਕੀ ਕਰਦਾ ਹੈ
ITERATOR → access elements of a collection SEQUENTIALLY without exposing its internals:
→ provides a standard way to traverse (next element, has more?)
→ the collection's internal structure (array, tree, linked list) is HIDDEN
→ decouples traversal logic from the collection
→ "iterate without caring how the collection is structured"
