Created
July 1, 2012 17:44
-
-
Save tadzik/3029085 to your computer and use it in GitHub Desktop.
Typed subroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test; | |
plan 9; | |
subset TwoArgSub of Sub where { | |
.signature.params == 2 | |
}; | |
my TwoArgSub $a; | |
lives_ok { $a = sub ($a, $b) { } }; | |
dies_ok { $a = sub () { } }; | |
dies_ok { $a = sub ($a) { } }; | |
dies_ok { $a = sub ($a, $b, $c) { } }; | |
subset TakesIntAndString of Sub where { | |
.signature.params == 2 | |
and .signature.params[0].type ~~ Int | |
and .signature.params[1].type ~~ Str | |
} | |
my TakesIntAndString $b; | |
lives_ok { $b = sub (Int $a, Str $b) { } }; | |
dies_ok { $b = sub (Int $a, $b) { } }; | |
dies_ok { $b = sub ($a, Str $b) { } }; | |
dies_ok { $b = sub (Str $a, Int $b) { } }; | |
dies_ok { $b = sub (Int $a, Str $b, $c) { } }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment