November 27, 2019 Re: Simple casting? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ixid | 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); } |
November 27, 2019 Re: Simple casting? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 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!
|
Copyright © 1999-2021 by the D Language Foundation