use collectFirst instand of a var and iterate

scala collection is not lazy, only scala Stream is lazy. 



Yours, Xuefeng Wu 吴雪峰 敬上

> On 2014年11月17日, at 上午9:21, Aaron Davidson <notifications@github.com> wrote:
> 
> In core/src/main/scala/org/apache/spark/util/Utils.scala:
> 
> > @@ -759,18 +759,9 @@ private[spark] object Utils extends Logging {
> >      if (file != null) {
> >        try {
> >          if (file.isDirectory && !isSymlink(file)) {
> > -          var savedIOException: IOException = null
> > -          for (child <- listFilesSafely(file)) {
> > -            try {
> > -              deleteRecursively(child)
> > -            } catch {
> > -              // In case of multiple exceptions, only last one will be thrown
> > -              case ioe: IOException => savedIOException = ioe
> > -            }
> > -          }
> > -          if (savedIOException != null) {
> > -            throw savedIOException
> > -          }
> > +          listFilesSafely(file).map(child => Try(deleteRecursively(child))).
> Will this continue to try to delete the remaining directories if one fails? That depends on the laziness of the underlying data structure, right?
> 
> This is certainly more concise, but I'm not sure it's clearer. I think the latter is more important, especially when dealing with potential failure scenarios.
> 
> —
> Reply to this email directly or view it on GitHub.
>