Simple casting?

ixid adamsibson at gmail.com
Wed Nov 27 22:01:10 UTC 2019


On Wednesday, 27 November 2019 at 14:40:56 UTC, Timon Gehr wrote:
> On 27.11.19 11:43, ixid wrote:
>> On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:
>>> import std;
>>> void main(){
>>>     int[] x=[1,1,2,3,4,4];
>>>     int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
>>>     writeln(y);
>>> }
>> 
>> This stuff is a nightmare for less experienced users like 
>> myself, I wish there were a single function that would make 
>> any data obkect eager, no matter how convoluted its arrays of 
>> arrays of arrays.
>
> import std;
>
> auto eager(T)(T r){
>     static if(isInputRange!T) return r.map!eager.array;
>     else return r;
> }
>
> void main(){
>     int[] x=[1,1,2,3,4,4];
>     int[][] y=x.chunkBy!((a,b)=>a==b).eager;
>     writeln(y);
> }

Thank you, this is great but it should be in Phobos!


More information about the Digitalmars-d-learn mailing list