-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathpackage.scala
52 lines (38 loc) · 1.84 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.tinkerpop.gremlin
import java.util.function.{ Function ⇒ JFunction, Predicate ⇒ JPredicate, BiPredicate }
import com.tinkerpop.gremlin.process.Traverser
import com.tinkerpop.gremlin.scala.GremlinScala._
import shapeless._
import shapeless.ops.hlist._
package object scala {
type Vertex = structure.Vertex
type Edge = structure.Edge
type Element = structure.Element
type Graph = structure.Graph
implicit def wrap(v: Vertex) = ScalaVertex(v)
implicit def wrap(e: Edge) = ScalaEdge(e)
implicit def wrap(g: Graph) = ScalaGraph(g)
implicit def unwrap(g: ScalaGraph) = g.graph
implicit def toElementSteps[End <: Element, Labels <: HList](gremlinScala: GremlinScala[End, Labels]) =
new GremlinElementSteps(gremlinScala)
implicit def toVertexSteps[End <: Vertex, Labels <: HList](gremlinScala: GremlinScala[End, Labels]) =
new GremlinVertexSteps(gremlinScala)
implicit def toEdgeSteps[End <: Edge, Labels <: HList](gremlinScala: GremlinScala[End, Labels]) =
new GremlinEdgeSteps(gremlinScala)
//TODO make vertexSteps extend elementSteps and return VertexSteps here
implicit def toElementSteps(v: ScalaVertex): GremlinElementSteps[Vertex, HNil] = v.start
implicit def toElementSteps(e: ScalaEdge): GremlinElementSteps[Edge, HNil] = e.start
implicit def toJavaFunction[A, B](f: Function1[A, B]) = new JFunction[A, B] {
override def apply(a: A): B = f(a)
}
implicit def toJavaPredicate[A](f: Function1[A, Boolean]) = new JPredicate[A] {
override def test(a: A): Boolean = f(a)
}
//converts e.g. `(i: Int, s: String) ⇒ true` into a BiPredicate
implicit def toJavaBiPredicate[A, B](predicate: (A, B) ⇒ Boolean) =
new BiPredicate[A, B] {
def test(a: A, b: B) = predicate(a, b)
}
implicit def liftTraverser[A, B](fun: A ⇒ B): Traverser[A] ⇒ B =
{ t: Traverser[A] ⇒ fun(t.get) }
}