A system such as Perl 6 is not flexible enough to declare such restrictions declaratively, but you can add a where clause to your parameter to check incoming arguments for a user expression.
For clarity, I would measure the expression to test each number in a subset :
subset SpecialNumber of Numeric where { $_ > 7 # (3), (4) && $_ !%% 2 # (5), since "odd" implies "not even" && .narrow ~~ Int # (5), since "odd" implies "integer" && ($_ - 1) ** (1/2 | 1/3) %% 2 # (6) } sub specialFunc(List $x where .all ~~ SpecialNumber ) { ... }
You can go one step further and split the whole where clause into a subset :
subset SpecialList of List where .all ~~ SpecialNumber; sub specialFunc(SpecialList $x) { ... }
PS: I think your requirement (5) may be redundant, since requirement (6) seems to satisfy only odd numbers, but I'm not big in number theory, so I'm not sure.
source share