Let's say you have a Scala function which takes type parameter:
def myFunc[K]: T
Let's say I have several functions like that. Right now, if K could be one of several different values, I'd need some code like the following:
kType match {
case KIsInt => myFunc[Int]
case KIsLong => myFunc[Long]
}
I'd like a generic wrapper function that can switch on kType and call different functions. Is this possible? Something like this.
def kFuncCall[T](kType: KType)(callFunc: [K] => T): T = {
kType match {
case KIsLong => callFunc[Long]
case KIsInt => callFunc[Int]
}
@gclaramunt: so the above code works for different KType's, but if I need something to work with type classes and implicits then it doesn't work. IE, what if callFunc is actually
def callFunc[K: SomeTypeClass]: List[K]
The problem is then that Scala won't be able to find the implicit based on kType.K