0
votes

I have created the following function:

 def mapToPers(inTuple: (String, String, String), 
               v: ((Double, Double, Double, Double, Double),
                   Map[Double,
                       (Double, Double, Double, Double, Double)])) = {

      val (prod: String, market: String, week: String) = inTuple
      val result = for (cumePeriod <- cumePeriods) yield {
        val (per, weekList) = cumePeriod
        if (weekList.contains(week)) ((prod, market, per), v)        
  }
 result
}

When I call it, it gives error of type mismatch:

Description Resource Path Location Type type mismatch; found : ((String, String, String), ((Double, Double, Double, Double, Double), Map[Double,(Double, Double, Double, Double, Double)])) => scala.collection.immutable.Iterable[Any] required: (((String, String, String), ((Double, Double, Double, Double, Double), Map[Double,(Double, Double, Double, Double, Double)]))) => TraversableOnce[?]

1
Please, what's the output println(inTuple) and println(cumePeriods). Also from where does v come from?Onilton Maciel
What is the type of cumePeriods ?Onilton Maciel
Instead of creating so crazy tuples , you'd better to create separate case class for each of them. It much easier to bug fix/investigate.vvg

1 Answers

3
votes

You clearly have a problem with nested tuples. Check the parentheses:

found :

(
  (String, String, String), 
  (
    (Double, Double, Double, Double, Double), 
    Map[Double,(Double, Double, Double, Double, Double)]
  )
) => scala.collection.immutable.Iterable[Any] 

required:

(
  (
    (String, String, String), 
    (
      (Double, Double, Double, Double, Double), 
      Map[Double,(Double, Double, Double, Double, Double)]
    )
  )
) => TraversableOnce[?]

So I see one more level of nesting. Hard to spot given the very confusing types, I would recommend you use some case classes here.

Edit: BTW, I Spotted something else. The if you are using does not have an else, so the for comprehension will not know what to yield exactly. You might want to yield only after checking:

val result = for { 
  (per, week_list) <- cumePeriods
  if week_list.contains(week)
}
  yield ((prod, market, per), v)