Let imagine I have the following traits/classes hierarchy ( scala 2.13 )
trait In
trait Out
case class In1() extends In
case class In2() extends In
case class Out1() extends Out
case class Out11() extends Out
case class Out2() extends Out
I'd like to write function that:
- In the case where
In1was sent as a param will only allow the return ofOut1orOut11object - In the case where
In2was sent as a param will only allow the return ofOut2object - Will check it on compile time
Unfortunately, I wasn't able to achieve it on my own even using external libs.
Could you please help or clarify if it possible at all ?
There are multiple ways to do what you are asking, but it is not clear which one would be more suitable to your use case than others ... because you didn't really describe you use case :)
This one is, probably, the simplest/most straight-forward: