Scala: What is the difference between Traversable and Iterable traits in Scala collections?

Rahul picture Rahul · Sep 15, 2011 · Viewed 17.5k times · Source

I have looked at this question but still don't understand the difference between Iterable and Traversable traits. Can someone explain ?

Answer

Duncan McGregor picture Duncan McGregor · Sep 15, 2011

Think of it as the difference between blowing and sucking.

When you have call a Traversables foreach, or its derived methods, it will blow its values into your function one at a time - so it has control over the iteration.

With the Iterator returned by an Iterable though, you suck the values out of it, controlling when to move to the next one yourself.