Why can't I find the length of an Iterable


#1

I notice when looking at the documentation of the Iterable class
https://www.scala-lang.org/api/current/scala/collection/Iterable.html
That there is no length method. I was thinking this is probably because an Iterable is not guaranteed to have finite length. However, it does have a count method.
So I can easily use it.count(a=>true)

What is the rational for not having a length function, but having a count function? Isn’t this inconsistent?


#2

It has size, which is defined at the root of the collections hierarchy. length is available (in addition to size) on sequences.


#3

is there a difference between length and size?


#4

No, the scaladoc says:

Note: xs.length and xs.size yield the same result


#5

is there a difference between length and size?

There is a discussion about this here.