I'm still new to context bounds in Scala and I'm trying to write a function that can perform a reduceByKey on any any generic that satisfies a context bound. eg
def myReduce[K: ClassTag, V: ClassTag: Numeric[V]](in: RDD[(K, V)]): RDD[(K, V)] = {
in.reduceByKey{case (v1, v2) =>
implicityly[Numeric[V]].plus(v1, v2)
}
As far as I understand this should work however when trying to compile I get the following errors.
- error: could not find implicit value for parameter e: Numeric
- error: Numeric[V] does not take type parameters
These I don't understand. I'm not passing in type parameters to Numeric[V] anywhere. Also shouldn't the context bound automatically import the 'evidence' for the conversion?
I was hoping to instead to eventually use my own trait instead of Numeric.
Edit:
I tried explicitly writing the implicit evdience in the function as follows:
def myReduce[K: ClassTag, V: ClassTag](in: RDD[(K, V)])(implicit ev: V => Numeric[V]): RDD[(K, V)] = {
in.reduceByKey{case (v1, v2) =>
implicityly[Numeric[V]].plus(v1, v2)
}
But I still get the "error: could not find implicit value for parameter e: Numeric" error.