scala - flatMap on class with parameterized type wont compile -


can tell me why following:

case class item[a, b, c](a : a, b: b, c: c) val s1 = seq(1, 2, 3) val s2: seq[item[_,_,_]] = seq(item(3, "q", "r"), item(4, "s", "t"), item(5, "u", "v")) s1.flatmap { =>   s2.find(_.a == i) match {     case some(i2) => some(item(i2.a, i2.c, i2.b))     case none => none   } } 

gives me following compiler errors , best way around it:

- no type parameters method flatmap: (f: int => scala.collection.gentraversableonce[b])(implicit bf:       scala.collection.generic.canbuildfrom[seq[int],b,that])that exist can applied arguments (int => iterable[item[_0]] forsome { type _0 }) ---       because --- argument expression's type not compatible formal parameter type; found : int => iterable[item[_0]] forsome { type _0 } required: int       => scala.collection.gentraversableonce[?b] - cannot construct collection of type elements of type b based on collection of type seq[int]. - cannot construct collection of type elements of type b based on collection of type seq[int]. 

making item covariant indeed make compile:

case class item[+a, +b, +c](a : a, b: b, c: c) ... 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

How do you convert a timestamp into a datetime in python with the correct timezone? -