How to reuse a signature?

Is it possible to assign a signature to a variable and then reuse it in different functions / methods? I found my $sig = :($a, $b);, but I don’t know how to use this variable as a signature in a function.

+4
source share
1 answer

One of the methods:

my $sig = :( $a, $b );

sub foo ( &function where { .signature ~~ $sig } ) {}

sub bar    ( $p, $q ) {}
sub qux    ( $waldo ) {}

foo &bar;

say "OK at line 10"; # OK at line 10

foo &qux;            # Constraint type check failed ... line 12".
+4
source

Source: https://habr.com/ru/post/1677628/


All Articles