[英]Scala: How to return a tuple in a function? "type mismatch"
我正在使用庫gremlin-scala
與 Janusgraph 進行交互。
使用 DSL,插入新頂點的一種方法是執行以下操作:
val Id = Key[Long]("id")
val Name = Key[String]("name")
graph + ("label", Id -> 42, Name -> "Mike")
我想把這部分變成一個函數("label", Id -> 42, Name -> "Mike")
case class VertexModel(id: Long, name: String) {
def toVertex: (Label, KeyValue[Long], KeyValue[String]) = {
val Id = Key[Long]("id")
val Name = Key[String]("name")
("item", Id -> id, Name -> name)
}
}
val model = VertexModel(1, "Bill")
graph + model.toVertex
這失敗並出現以下錯誤:
Error:(26, 11) type mismatch;
found : T1
required: gremlin.scala.Label
(which expands to) String
graph + vertex
Error:(26, 11) type mismatch;
found : T2
required: gremlin.scala.KeyValue[Long]
graph + vertex
Error:(26, 11) type mismatch;
found : T3
required: gremlin.scala.KeyValue[String]
graph + vertex
不知道如何解決這個問題。
為什么需要擴展方法toVertex
?
這不就像
import gremlin.scala._
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
object App {
implicit val graph: ScalaGraph = TinkerGraph.open.asScala
case class VertexModel(id: Long, name: String)
val model = VertexModel(1, "Bill")
graph + model
}
?
生成.sbt
scalaVersion := "2.12.8"
libraryDependencies += "com.michaelpollmeier" %% "gremlin-scala" % "3.4.0.4"
libraryDependencies += "org.apache.tinkerpop" % "tinkergraph-gremlin" % "3.4.0"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.