automate tuple creation
forkit
forkit at gmail.com
Fri Jan 21 03:45:08 UTC 2022
On Friday, 21 January 2022 at 02:30:35 UTC, Ali Çehreli wrote:
>
> The bigger question is, why did 'formattedRecords' exist at
> all? You could have written the output directly to the file.
Oh. this was intentional, as I wanted to write once, and only
once, to the file.
The consequence of that decision of course, is the extra memory
allocations...
But in my example code I only create 10 records. In reality, my
dataset will have 100,000's of records, so I don't want to write
100,000s of time to the same file.
> But even *worse* and with apologies, ;) here is something crazy
> that achieves the same thing:
>
> void ProcessRecords
> (in int[][int][] recArray, const(string) fname)
> {
> import std.algorithm : joiner;
> auto toWrite = recArray.map!(e => e.byPair);
> File("rnd_records.txt",
> "w").writefln!"%(%(%(%s,%(%s,%)%)%)\n%)"(toWrite);
> }
>
> I've done lot's of trial and error for the required number of
> nested %( %) pairs. Phew...
>
> Ali
Yes, that does look worse ;-)
But I'm looking into that code to see if I can salvage something
from it ;-)
More information about the Digitalmars-d-learn
mailing list