Note that you can also use subset to create a type: subset ArrayOfStr of Array where .all ~~ Str;
sub foo (@a where ArrayOfStr) {...} or: sub foo (ArrayOfStr $a) {...} On 2017-01-08 10:33:36 GMT, Fernando Santagata wrote: > Thank you! > > On Sat, Jan 7, 2017 at 5:23 PM, Siavash <siavash.askari.n...@gmail.com> > wrote: > >> >> Hi, >> >> If you really want to avoid `Array[Str].new`, you can do something like >> this: >> >> sub foo (@a where .all ~~ Str) {...} >> >> On 2017-01-07 11:45:55 GMT, Fernando Santagata wrote: >> > Hello, >> > >> > I have a function like this: >> > >> > sub test(Str :$format, :@filter) >> > { >> > say $format; >> > say @filter; >> > } >> > >> > and I wish to have a stricter type control over the second parameter. >> > >> > The natural way to do it seemed this: >> > >> > sub test(Str :$format, Array[Str] :$filter) >> > { >> > say $format; >> > say $filter; >> > } >> > >> > but then I have to call it this way: >> > >> > test format => 'gnutar', filter => Array[Str].new('gzip', 'uuencode'); >> > >> > Is there a less cumbersome way to do it? >> > >> > Obviously this doesn't work: >> > >> > test format => 'gnutar', filter => <gzip uuencode>; >> > >> > because the argument is interpreted as a generic List. >> > This doesn't work either: >> > >> > test format => 'gnutar', filter => ['gzip', 'uuencode']; >> > >> > because it's interpreted as a generic Array, not an Array[Str]. >> > >> > Thank you! >> >>