Created
September 6, 2011 05:22
-
-
Save zcox/1196660 to your computer and use it in GitHub Desktop.
FluentPipeline Scala Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.tinkerpop.blueprints.pgm._ | |
import com.tinkerpop.blueprints.pgm.impls.tg._ | |
import com.tinkerpop.pipes._ | |
import com.tinkerpop.pipes.util._ | |
import scala.collection.JavaConversions.asScalaIterator | |
import java.lang.{Boolean => JBoolean} | |
val graph = TinkerGraphFactory.createTinkerGraph() | |
//Adapter from T => Boolean to PipeClosure along with an implicit conversion | |
class Function1PipeClosure[T](f: T => Boolean) extends AbstractPipeClosure[JBoolean, Pipe[_, _]] { | |
override def compute(objects: Object*): JBoolean = f(objects(0).asInstanceOf[T]) | |
} | |
implicit def fToFunction1PipeClosure[T](f: T => Boolean) = new Function1PipeClosure[T](f) | |
//Now we can pass a function literal instead of an AbstractPipeClosure to filter | |
val fp = new FluentPipeline[Vertex, String](graph getVertex 1) out "knows" property "name" filter { s: String => s startsWith "j" } | |
for (friendName <- fp) println(friendName) | |
//output is just "josh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment