Foreach Closures?

Dmitry Olshansky dmitry.olsh at gmail.com
Tue Apr 10 03:57:22 PDT 2012


On 10.04.2012 14:06, 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
>

Yeah recent change allowed to use straight alias this in DirEntry struct 
thus there is no need for separate opApply now.

> 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


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list