Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Iterator and Iterable [duplicate]

What is the difference between Iterator and Iterable? Is one sub-type of the other or not? What are the actual differences in some real applications?

I am trying to read some tutorials and specifications, but they are all very complicated.

(I am using ES6 and Babel, if that helps.)

like image 758
Karel Bílek Avatar asked Apr 26 '16 19:04

Karel Bílek


1 Answers

From Exploring ES6 by Dr. Axel Rauschmayer:

An iterable is a data structure that wants to make its elements accessible to the public. It does so by implementing a method whose key is Symbol.iterator. That method is a factory for iterators.

An iterator is a pointer for traversing the elements of a data structure (think cursors in databases).

like image 197
Роман Парадеев Avatar answered Sep 27 '22 19:09

Роман Парадеев