Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created March 8, 2010 16:50
Show Gist options
  • Save rrichardson/325339 to your computer and use it in GitHub Desktop.
Save rrichardson/325339 to your computer and use it in GitHub Desktop.
trait NeoIterable[T] extends Iterator[T] {
def first() : T = {
this.take(1).toList.head
}
}
implicit def jiterable2iterable[T](it: java.lang.Iterable[T]) = new Wrapper[T](it.iterator()) with NeoIterable[T]
use:
class RichNode(node: Node) {
object getOtherNodes {
def apply() : Iterable[Node] = getNodesFromRels(node.getRelationships())
def apply(dir : Direction) : Iterable[Node] = getNodesFromRels(node.getRelationships(dir))
def apply(rel : RelationshipType, dir : Direction) : Iterable[Node] = getNodesFromRels(node.getRelationships(rel, dir))
def apply(rel : RelationshipType) : Iterable[Node] = getNodesFromRels(node.getRelationships(rel))
private def getNodesFromRels(rels : Iterable[Relationship]) : Iterable[Node] = rels.map { r =>
r.getOtherNode(node)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment