www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3459] New: There should be a flavor of file.listdir() that returns a range instead of taking a delegate

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3459

           Summary: There should be a flavor of file.listdir() that
                    returns a range instead of taking a delegate
           Product: D
           Version: 2.035
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: llucax gmail.com


--- Comment #0 from Leandro Lucarella <llucax gmail.com> 2009-10-30 21:21:07
PDT ---
This idiom:

----
foreach (f; listdir(some_dir))
    writeln(f);
----

is much more simpler, convenient and clearer than:

----
listdir(some_dir, (string f) { writeln(f) });
----

Which looks more obscure (specially when the callback is more complex.

The first idiom was not possible in D1 without allocating an array for the
elements, which can be inefficient, but with ranges in place in D2, I think
listdir() should use them.

Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3459


Leandro Lucarella <llucax gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #1 from Leandro Lucarella <llucax gmail.com> 2009-10-30 21:35:15
PDT ---
OMG! listdir is a opApply candidate, so foreach can be used already with it...

Damn! I should go to bed...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2009