Reputation: 3838
The following method definition:
def validClasses(dataType: DataType) = {
examples
.flatMap {
v: Any =>
Try {
val canon = toCanonicalType(v, dataType)
canon.getClass
}
.toOption
.toSet
}
}
yield the following error:
Error:(94, 8) no type parameters for method flatMap: (f: Any => scala.collection.GenTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Set[Any],B,That])That exist so that it can be applied to arguments (Any => scala.collection.immutable.Set[Class[?0]] forSome { type ?0 })
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Any => scala.collection.immutable.Set[Class[?0]] forSome { type ?0 }
required: Any => scala.collection.GenTraversableOnce[?B]
.flatMap {
^
Which is strange. As the result of toSet is not a a Set[Class[?0]] forSome { type ?0 }. Is there any way to fix this problem?
Upvotes: 0
Views: 213
Reputation: 170713
As the result of toSet is not a a Set[Class[?0]] forSome { type ?0 }.
Yes, it is: .getClass
returns a Class[_]
, so Try { ... }
is a Try[Class[?0]] forSome { type ?0 }
(?0
is just a variable name generated by the compiler), and .toOption.toSet
is a Set[Class[?0]] forSome { type ?0 }
.
Upvotes: 1