On 11/26/19 2:08 PM, Taylor R Hillegeist wrote:> On Tuesday, 26 November
2019 at 16:33:06 UTC, Timon Gehr wrote:
>> int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
>
>
> how did you know to do that?
Ranges don't have elements. They either generate elements according to
an algorithm, provide access to elements (or copies of elements) that
belong to other containers.
In this case, chunkBy() is like an engine that knows how to present the
input range in chunks but does not start working automatically. This is
a great feature because you can start accessing chunks, deciding it's
enough, and stop; potentially avoiding a lot of eager work (potentially
infinite).
std.array.array pulls all elemenst of a range and places them inside an
array. That is eager but sometimes necessary work. For example,
std.algorithm.sort cannot sort just any range because it needs the
elements to be layed out as array elements:
someAlgorithmRange.sort; <-- Does not work
someAlgorithmRange.array.sort <-- Works
Ali