IteratorOnce[T]#copyToArray could return number of elems written rather than the array written to


I’m not sure if this is where the Scala team wants people to discuss even minor ideas like this, but the website ( indicates one should be very sure that what they are submitting is a bug before opening an issue. Wouldn’t it be better to have some kind of issue tracker for ideas/design/things that aren’t necessarily bugs?

Anyways I have just come to suggest that these three copyToArray methods on IterableOnce could return the number of elements written to the array passed in, rather than returning the array itself. My reasoning is that

  1. the number of elements written to the array is non-deterministic – the IteratorOnce may run out of elements at any time. It doesn’t seem very easy to determine which elements written to the array are actually newly written elements after the method returns since of course they all have the same type.

  2. The caller of the method of course already has access to the Array[T], so not much is lost by not returning the array, except if anyone really wants to avoid assigning the array to an identifier.

The methods in question are:


Edit: Sorry, I found the issue tracker, at I would delete this thread but it doesn’t look like that is possible on discord.