I think it would be better to have
def childrenRecursively: Iterable[File]
method, that returns all children recursively, but lazily, i. e. it
does evaluation when it elements accessed.
S.
On Thu, Jul 24, 2008 at 18:49, Jesse Eichar <
jesse.eichar@...> wrote:
> I have a request for the FileExtras class (I'm willing to write the code and
> the tests if my proposal is accepted). I have found my self having to over
> and over write a method for recursing through a directory graph and doing
> something to many or all of the files. For example I might be deleting all
> .svn directories or some other task.
>
> Probably the reason for this is because I am introducing Scala at my company
> through scripts and maybe a tool for automated builds (although I'm less
> convinced this is a good idea).
>
> Feel free to shoot me down but it does seem like a useful method for the
> FileExtras class.
>
> The obvious way to implement it is in a "in-order" traversal. Something
> like the following:
>
>> import java.io.File
>>
>> def eachChildRecursive( parent:File, function:File=>Unit ):Unit = {
>> parent.listFiles.foreach { child =>
>> function(child)
>> if(child.isDirectory())
>> eachChildRecursive(child,function)
>> }
>> }
>>
>> val here = new File(".")
>>
>> eachChildRecursive( here, println _ )
>
> However by calling the function after the if statement we could perform a
> depth-first traversal.
>
> Is there any desire by anyone else to see this in the library? I have
> already written it at least 5 times which means it will go into my private
> library otherwise. Seeing that ScalaX has a much wider audience I thought
> to offer my services in writing for scalax.
>
> Jesse
>
>