I am trying to set a default value (x) => x for the parameter keyFunction in the following function:
def count[A, B](list: List[A], keyFunction: (A) => B, isRatio : Boolean = false): Map[B, Double] = {
lazy val number = list.size.toDouble
list.groupBy(keyFunction).map{
case (key, group) => if (isRatio) (key, group.size/number) else (key, group.size.toDouble)
}
}
I know a dumb solution is just to define another function:
def simplyCount[A] (list: List[A], isRatio: Boolean = false): Map[A, Double] = count(list, (e: A) => e, isRatio)
How can I do it in a better way? Thanks in advance.