This repository was archived by the owner on Dec 22, 2021. It is now read-only.
  
  
  
  
  
Description
Sometimes we want to build a collection from just an IterableOnce. In such a case, we can wrap the IterableOnce in a View (which is an Iterable) to pretend it is an Iterable but this is not actually the case and will break if one attempts to perform multiple traversals.
One way to solve this problem would be to change the signature of fromIterable as follows:
- def fromIterable[A](it: Iterable[A]): CC[A]
+ def fromIterable[A](it: IterableOnce[A]): CC[A]
Thus it would be clear for factory implementations that they should not perform multiple traversals. (they could still check at runtime if the given IterableOnce is an instance of Iterable if needed).
We might also consider moving the knownSize to IterableOnce (because one reason to perform several traversals is to compute the size of the collection, which could be avoided in some cases).
As suggested by @szeiger we could also make it more explicit that the View.fromIterator takes a thunk as parameter:
- def fromIterator[A](it: => Iterator[A]): View[A]
+ def fromIteratorProvider[A](it: () => Iterator[A]): View[A]