I have looked at this question but still don’t understand the difference between Iterable and Traversable traits. Can someone explain ?
I have looked at this question but still don’t understand the difference between Iterable
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To put it simply, iterators keep state, traversables don’t.
A
Traversablehas one abstract method:foreach. When you callforeach, the collection will feed the passed function all the elements it keeps, one after the other.On the other hand, an
Iterablehas as abstract methoditerator, which returns anIterator. You can callnexton anIteratorto get the next element at the time of your choosing. Until you do, it has to keep track of where it was in the collection, and what’s next.