Impressed

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jul 27 15:38:27 PDT 2012


On 27-Jul-12 22:58, Stuart wrote:
> On Friday, 27 July 2012 at 16:15:46 UTC, Jesse Phillips wrote:
>>
>> Taking a look at DirIteratorImpl[1] in std.file suggest there is a lot
>> of setup to navigate the filesystem on Windows. How does Yield help
>> with that logic?
>
> Well, off the top of my head, you could use something like:
>
>     Public Iterator Function AllFiles(RootDirectory As String) As
> IEnumerable(Of String)
>        Dim Roots As New Queue(Of String) From {RootDirectory}
>        While Roots.Any
>           Dim Root = Roots.Pop
>           Roots.AddRange(IO.Directory.GetDirectories(Root))
>           For Each Filename in IO.Directory.GetFiles(Root)
>              Yield Filename
>           Next
>        End While
>     End Function
>

Then it's not in anyway better then ranges. You again maintain stack (or 
queue, whatever). The only difference is that for is replaced with a 
function front/popFront that do one iteration of the same state machine.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list