Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Generalize dirEntries to take a DirEntry predicate as parameter #8586

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -4783,6 +4783,8 @@ if (__traits(compiles, { DirEntry entry; bool _ = pred(entry); }))

bool mayStepIn()
{
if (!pred(_cur))
return false;
return _followSymlink ? _cur.isDir : attrIsDir(_cur.linkAttributes);
}
}
Expand Down Expand Up @@ -5198,6 +5200,12 @@ if (__traits(compiles, { DirEntry entry; bool _ = pred(entry); }))
sort(result);

assert(equal(files, result));

import std.algorithm : endsWith;
auto result2 = dirEntries!((scope ref DirEntry entry) => entry.name.endsWith("Hello World"))(dir, SpanMode.shallow).map!((return a) => a.name.normalize()).array();
import std.stdio;
writeln(result2);
LightBender marked this conversation as resolved.
Show resolved Hide resolved
assert(result2.length == 1);
}

// https://issues.dlang.org/show_bug.cgi?id=21250
Expand Down