Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse a signature?

Tags:

signature

raku

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

like image 291
sid_com Avatar asked May 21 '17 06:05

sid_com


1 Answers

One way:

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".
like image 56
raiph Avatar answered Sep 22 '22 11:09

raiph