Expand a list of cases in a subclass
Most probably what I want to do cannot be done, but hopefully something
similar is possible.
What I would like to do is having a match-case statement in a method in a
class A, creating a subclass B and keeping all the cases that are not
overwritten by my subclass, so that before the final case _ in the
subclass all the cases of the superclass A are attempted.
AFAIK this is very far from being possible (but please correct me if
wrong), but something similar is not that far from being possible.
A maybe possible option would be to have a map of cases and functions in
the superclass and expanding that map in each subclass. The cases should
be of the type [T1] => Bool, the functions should be of the type [T1] =>
[T2], where T2 is the return type of the method we are expanding in the
subclass. Then a loop should be run until one case returns true and its
function is executed.
The problem is that I am uncertain about how to define those cases ([T1]
=> Bool). Having a match for each one of them may be very inefficient.
This may also be deeply non-idiomatic and some other way to implement this
could be preferable.
No comments:
Post a Comment