D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3459 - There should be a flavor of file.listdir() that returns a range instead of taking a delegate
Summary: There should be a flavor of file.listdir() that returns a range instead of ta...
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-30 21:21 UTC by Leandro Lucarella
Modified: 2015-06-09 01:26 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Leandro Lucarella 2009-10-30 21:21:07 UTC
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.
Comment 1 Leandro Lucarella 2009-10-30 21:35:15 UTC
OMG! listdir is a opApply candidate, so foreach can be used already with it...

Damn! I should go to bed...