On Sunday, 10 December 2017 at 06:01:49 UTC, Ali Çehreli wrote:
On 12/09/2017 06:19 PM, Vino wrote:
[...]
When no seed value is specified, fold (and reduce) take the
first element as the seed. When the range is empty, then there
is a run-time failure:
object.Exception@/usr/include/dmd/phobos/std/algorithm/iteration.d(2794):
Cannot reduce an empty input range w/o an explicit seed value.
The solution is to provide an explicit seed value:
import std.container;
import std.file;
import std.algorithm;
void main() {
const d = "/tmp/empty_folder";
const Size = 42;
auto SdFiles = Array!ulong(dirEntries(d,
SpanMode.depth).map!(a => a.size).fold!((a,b) => a +
b)(size_t(0)))[].filter!(a => a > Size);
}
I chose size_t(0) but you can use a variable, size_t.init, etc.
Ali
Hi Ali,
Thank you very much, was able to apply your logic which resolved
the issue.
From,
Vino.B