scala: not possible to match on value expressions? -
why isn't possible place expressions in case statements? :
x match { case <value expr> => {} }
for example
x match { case (1+2) => {} }
is not allowed, but
val someval = (1+new java.util.random().nextint()) x match { case someval => {} }
is. seems if second case allowed, should first.
i'm trying add list of mappings this:
val typ:type = symbol.typesignature typ match { case typeof[collection.immutable.list[any]] => { return function handle type } case typeof[...] => {} case typeof[...] => {} ... many }
it defies definition of patterns in pattern matching.
from scala language specification, chapter 8:
a pattern built constants, constructors, variables , type tests
"expressions" not in list, , makes sense - think - when expression evaluated? if has side-effects, evaluated if case preceding used return result?
a valid workaround using guard, is evaluated:
x match { case if == (1+2) => {} // works expected... }
Comments
Post a Comment