Foreach Closures?

Timon Gehr timon.gehr at gmx.ch
Tue Apr 10 03:47:08 PDT 2012


On 04/10/2012 12:06 PM, Andrej Mitrovic wrote:
> On 4/10/12, Dmitry Olshansky<dmitry.olsh at gmail.com>  wrote:
>> Wake up! dirEntries produce a lazy _range_ and it's not opApply
>
> Sorry? Change DirIterator in std.file to this:
> http://pastebin.com/DHvXuFeH
>

You are doing it wrong.
Use:
if(auto r=dg(s)) return r;
instead.

> test.d:
> import std.file;
>
> bool isEmptyDir(string path)
> {
>      foreach (string name; dirEntries(path, SpanMode.shallow))
>          return false;
>
>      return true;
> }
>
> void main()
> {
>      isEmptyDir(".");
> }
>
> $ rdmd test.d
>> we're in oppapply



More information about the Digitalmars-d mailing list