As it turns out, inputRangeObject does an excellent job at this task. The solution then becomes something like:

InputRange!string getEntries(string[] paths, bool recursive)
{
    auto files = paths.filter!(p => p.isFile);

    if (recursive) {
        auto expandedDirs = paths
            .filter!(p => p.isDir)
            .map!(p => dirEntries(p, SpanMode.depth, false))
            .joiner
            .map!(de => de.name);

        return inputRangeObject(chain(files, expandedDirs));
    }
    else {
        foreach (dir; paths.filter!(p => p.isDir))
            stderr.writeln("omitting directory " , dir);

        return inputRangeObject(files);
    }
}

Reply via email to