I’ve got a following situation:
Got a method def f(lst: List[Any]), which does some transformation of the list and returns result of that transformation (all those Any‘s are case classes). What I need to accomplish is when the input list is empty, generate a list, containing one element of the correct type and do that transformation with it.
Is it possible to guarantee on a type level, that some case class has a no-arg constructor? If so, what should Any be replaced with? If no, what is the best way to accomplish this? Maybe I should just change my method to something like def f[T](lst: List[T], default: T)?
Any help appreciated.
Are you looking for something like this?
If yes, you can refer to this post I wrote on the subject a while ago.