Scala:如何 return 函数中的元组? "type mismatch"

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
}

?

build.sbt

scalaVersion := "2.12.8"
libraryDependencies += "com.michaelpollmeier" %% "gremlin-scala" % "3.4.0.4"
libraryDependencies += "org.apache.tinkerpop" % "tinkergraph-gremlin" % "3.4.0"