Вот определения функций, которые отлично работают:
case class Type(unique:String, tech:String)
case class TVal(tech:String, value:String)
def f1(techName:String, variables: List[TVal]):String =
variables.filter(variable =>
techName == variable.tech)
.map(variable => variable.value) match {
case Nil => "empty list"
case head::Nil => head
case head::tail => "more than one"
}
def f2(defList:List[Type],
variables: List[TVal]):List[Tuple2[String,String]] =
defList.map(t => {
t.unique -> f1(t.tech, variables)
})
def comp(defList:List[Type],
variables: List[TVal]):Map[String,String] =
Map(f2(defList, variables): _*)
Теперь я пытаюсь заменить каждый вызов функции своим телом:
def compSubstitution(defList:List[Type],
variables: List[TVal]):Map[String,String] =
Map(defList.map(t => {
t.unique -> variables.filter(variable =>
t.tech == variable.tech)
.map(variable => variable.value) match {
case Nil => "empty list"
case head::Nil => head
case head::tail => "more than one"
}
}): _*)
Теперь я получаю ошибки компиляции:
Error:(33, 14) pattern type is incompatible with expected type;
found : scala.collection.immutable.Nil.type
required: (String, List[String])
case Nil => "empty list"
Error:(33, 14) type mismatch;
found : scala.collection.immutable.Nil.type
required: (String, List[String])
case Nil => "empty list"
Error:(34, 18) constructor cannot be instantiated to expected type;
found : scala.collection.immutable.::[B]
required: (String, List[String])
case head::Nil => head
Error:(35, 18) constructor cannot be instantiated to expected type;
found : scala.collection.immutable.::[B]
required: (String, List[String])
case head::tail => "more than one"
Error:(29, 20) type mismatch;
found : List[String]
required: Seq[(String, String)]
Map(defList.map(t => {
Как это могло быть? Можете ли вы описать?