Hi Todd, is this what you're looking for? sub mysub(Int $value where * ~~ 1|2|4|8|16) { say "Got $value" }
mysub 2; # Got 2 mysub 3; # Constraint type check failed in binding to parameter '$value'; expected anonymous constraint to be met but got Int (3) On Sun, Mar 3, 2019 at 11:09 AM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > Hi All, > > I want to pass an integer to a sub. The only > valid values of the integer are 1, 2, 4, 8, and 16. > > Other than using "if" to test their values, is > there a way to state that an integer can only > have certain predefined values? > > Many thanks, > -T > > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Having been erased, > The document you're seeking > Must now be retyped. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~ > -- Fernando Santagata