Is it possible to combine guard conditions with pattern matching within sealed case class declarations?
I realise its possible to include guard conditions within the match block but I feel it would be beneficial to define this conditions up front in the sealed case classes. This would allow developers to define strict set of possible inputs which the compiler would check when pattern matching.
So in summary I'd like to be able to do the equivalent of something like this:
// create a set of pattern matchable cases with guards built in
sealed abstract class Args
case class ValidArgs1(arg1:Int,arg2:Int) if arg1>1 && arg2<10 extends Args
case class ValidArgs2(arg1:Int,arg2:Int) if arg1>5 && arg2<6 extends Args
case class InvalidArgs(arg1:Int,arg2:Int) if arg1<=1 && arg2>=10 extends Args
// the aim of this is to achieve pattern matching against an exhaustive set of
// pre-defined possibilities
def process(args:Args){
args match
{
case ValidArgs1 = > // do this
case ValidArgs2= > // do this
case InvalidArgs = > // do this
}
}