converting a iterable of Paths to a PathSet

45 views
Skip to first unread message

Jeff Olson

unread,
Dec 16, 2011, 4:12:52 PM12/16/11
to scala-i...@googlegroups.com

def pathsToPathSet(paths: Iterable[Path]): PathSet[Path] =
  new BasicPathSet[Path](paths, PathMatcher.All, 0, true, (p: Path) => p.children().toList)

Is this the correct way to do it? For the record it would be nice if

PathSet(paths.toSeq: _*)

worked as expected.

-Jeff

---------------------------------------------------------------
This email, along with any attachments, is confidential. If you 
believe you received this message in error, please contact the 
sender immediately and delete all copies of the message.  
Thank you.

Jesse Eichar

unread,
Dec 17, 2011, 3:24:22 AM12/17/11
to scala-i...@googlegroups.com, scala-i...@googlegroups.com
Basic pathset is basically an implementation and a tool for implementing custom paths.  So I definitely need to add PathSet(Path*).  Look for it in the next release.  Should be coming soon.

Thanks

Sent from my iPad

Jeff Olson

unread,
Dec 17, 2011, 2:58:56 PM12/17/11
to scala-i...@googlegroups.com
Awesome. Thanks!

Until I have the pleasure of using the new release, will the above do more or less what I think it does?

-Jeff

Jesse Eichar

unread,
Dec 17, 2011, 4:11:31 PM12/17/11
to scala-i...@googlegroups.com
It will almost do what you want.  My implementation is as follows:

new BasicPathSet(

        elements, PathMatcher.All, 1, true

        (m:PathMatcher[Path],e:Path) => (e.children(m)).iterator)


This implementation can handle filters and collects.  Yours will give the wrong result if you do:

pathset.filter( _.isDirectory )

because the function _.isDirectory will be passed to the children function and your implementation will ignore that filter.

I am in the process of writing tests so watch for updates to this thread as I will update if I find my implementation has bugs.

Hope that helps.


Jesse

Jeff Olson

unread,
Dec 17, 2011, 5:33:14 PM12/17/11
to scala-i...@googlegroups.com
Very much. Thanks again, and keep up the good work.

Jesse Eichar

unread,
Dec 18, 2011, 7:22:08 AM12/18/11
to scala-i...@googlegroups.com
Sometimes I forget to use my brain.  A solution usable in Scala-io 0.2 is:

val pathSet = Path("a") +++ Path("b")

Path's are PathFinder and have all the behaviour and composability of a PathFinder.  And so the above combines 2 PathFinders.  The Path implementation of +++ returns a PathSet[Path] so you should be set :)

Jesse

Jeff Olson

unread,
Dec 18, 2011, 12:58:59 PM12/18/11
to scala-i...@googlegroups.com
To be honest this is where I started from. It works great for two or more paths, but there is no empty or singleton path set. I can write a singleton path set just fine, but the empty one is more annoying. The only nontrivial method is

  def +++[U](includes: PathFinder[U]): PathSet[U] = includes // error PathFinder[U] is not a PathSet[U]

so I have to write a conversion from PathFinder to PathSet (I can't use AdditivePathSet since it's private). Okay, it's trivially to write, but it was more boilerplate than I wanted so I started looking for a more direct/efficient implementation.

Of course, once I have a EmptyPathSet I can write

  def pathsToPathSet(paths: Iterable[Path]): PathSet[Path] = paths.foldLeft(EmptyPathSet: PathSet[Path])(_ +++ _)

Perhaps I'll stick with this until you release the next version.

-Jeff

Jesse Eichar

unread,
Dec 18, 2011, 1:35:08 PM12/18/11
to scala-i...@googlegroups.com, scala-i...@googlegroups.com
Really? Hmmph. I Guess that was a fix I made Post 0.2 release. Good News is that +++ Works correctly now.

0.3.0 contains lots of PathSet fixes and performance enhancements.

Jesse

Sent from my iPad

Reply all
Reply to author
Forward
0 new messages