Cannot reduce an empty iterable w/o an explicit seed value
Vino
vino.bheeman at hotmail.com
Tue Nov 14 03:25:10 UTC 2017
On Thursday, 9 November 2017 at 13:24:45 UTC, Nicholas Wilson
wrote:
> On Thursday, 9 November 2017 at 12:40:49 UTC, Vino wrote:
>> [...]
>
> The problem is
> subdirTotalGB = ((reduce!((a,b) => a + b)(SdFiles)) / 1024 /
> 1024 / 1024);
> with reduce you need to give it a seed (an initial value to
> start with).
> See
> https://dlang.org/phobos/std_algorithm_iteration.html#.reduce
>
>> [...]
>
> To your actual use case, you can do:
>
> foreach (d; parallel(dFiles[], 1)) {
> float subdirTotalGB = dirEntries(join(["\\\\?\\", d]),
> SpanMode.depth)
> .filter!(a => a.isFile))
> .map!(a => to!float(a.size)))
> .fold!((a, b) => a + b)(0) // Provide an explicit seed.
>
> if (subdirTotalGB > SizeDir) {
> Result.insertBack(d);
> Result.insertBack(to!string(subdirTotalGB));
> }
> }
Hi,
Thank you very much and I wanted to use reduce function instead
of fold for accuracy purpose so i just added the below line and
it worked.
Code:
float x;
x = 0;
{subdirTotalGB = ((reduce!((a,b) => a + b)(x, SdFiles)) / 1024 /
1024 / 1024);}
More information about the Digitalmars-d-learn
mailing list