I\'m trying to write a generic mean function that operates on an Iterable that contains numeric types. It would operate, say, on arrays, as so:
val rand = n
One of your version is pretty close:
def mean[T](xs: Iterable[T])(implicit num: Numeric[T]):Double = num.toDouble(xs.sum) / xs.size
Here is the other syntax:
def mean[T: Numeric](xs: Iterable[T]):Double = implicitly[Numeric[T]].toDouble(xs.sum) / xs.size