I noticed that method combinations (from here) returns Iterator. It looks reasonable that the method should be "lazy" to avoid generating all combinations in advance. Now I wonder, why it returns Iterator instead of Stream (which is a lazy list in Scala).
So, why does combinations return Iterator rather than Stream ?
With
Streamit is more likely that all generated values will be held in memory.When you retain a reference to your
Stream, all generated elements will remain in memory. With anIteratorthis is less likely to happen.Of course this does not have to be the reason why the Scala library is designed the way it is…