Say I have a function that creates a list of objects. If I want to return an iterator, I'll have to return iter(a_list)
. Should I do this, or just return the list as it is? My motivation for returning an iterator is that this would keep the interface smaller -- what kind of container I create to collect the objects is essentially an implementation detail
On the other hand, it would be wasteful if the user of my function may have to recreate the same container from the iterator which would be bad for performance.