Hi,

On 07.01.2017 12:45, 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?

As you have discovered, you need to be explicit about the type of the
argument that's passed in.

You can use anonymous variables to write an Array[Str] more compact:

test format => 'gnutar', filter => my Str @ = 'gzip', 'uuencode';

or even

test format => 'gnutar', filter => my Str @ = <gzip uuencode>;

My general advise is to not exaggerate the usage of container types.
Think of Perl 6 as a dynamically typed language, and only add types
where they make life easier for everybody involved.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/

Reply via email to