Behavior of joining mapresults
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Thu Dec 21 07:41:50 UTC 2017
On Thursday, December 21, 2017 07:46:03 Christian Köstlin via Digitalmars-d-
learn wrote:
> On 20.12.17 17:30, Christian Köstlin wrote:
> > thats an idea, thank a lot, will give it a try ...
>
> #!/usr/bin/env rdmd -unittest
> unittest {
> import std.stdio;
> import std.range;
> import std.algorithm;
> import std.string;
> import std.functional;
>
> auto parse(int i) {
> writeln("parsing %s".format(i));
> return [1, 2, 3];
> }
>
> writeln(iota(1, 5).map!(memoize!parse));
> writeln("-------------------------------");
> writeln((iota(1, 5).map!(memoize!parse)).joiner);
> }
>
> void main() {}
>
> works, but i fear for the data that is stored in the memoization. at the
> moment its not a big issue, as all the data fits comfortable into ram,
> but for bigger data another approach is needed (probably even my current
> json parsing must be exchanged).
>
> I still wonder, if the joiner calls front more often than necessary. For
> sure its valid to call front as many times as one sees fit, but with a
> lazy map in between, it might not be the best solution.
I would think that it would make a lot more sense to simply put the whole
thing in an array than to use memoize. e.g.
auto arr = iota(1, 5).map!parse().array();
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list