Created
March 27, 2018 13:39
-
-
Save Scimon/87571079e09c51d4ee8756cfe6d99e58 to your computer and use it in GitHub Desktop.
Testing Perl6 Multi Dispatch
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
subset Seven of Int where * == 7; | |
multi sub foo() { 'No args' } | |
multi sub foo(5) { 'Called with 5' } | |
multi sub foo(Seven $) { 'Called with 7' } | |
multi sub foo( *@a ) { '*@a' } | |
multi sub foo( $a ) { '$a' } | |
multi sub foo( Cool $b ) { 'Cool $b' } | |
multi sub foo( Int $b ) { 'Int $b' } | |
multi sub foo( Int $b where * > 0 ) { 'Int $b where * > 0' } | |
multi sub foo2( $a ) { '$a' } | |
multi sub foo2( *@a ) { '*@a' } | |
multi sub foo3( *@a ) { '*@a' } | |
multi sub foo3( $a ) { '$a' } | |
multi sub foo4( *@a where { one(@_) } ) { '*@a with 1 True' } | |
multi sub foo4( *@a where { all(@_) } ) { '*@a with all True' } | |
multi sub foo4( *@a where { none(@_) } ) { '*@a with all False' } | |
multi sub foo4( *@a where { any(@_) } ) { '*@a with at least 1 True' } | |
multi sub foo4() { 'Empty' } | |
say "foo"; | |
say foo(); | |
say foo(0); | |
say foo("a"); | |
say foo(0,1); | |
say foo(1); | |
say foo(5); | |
say foo(7); | |
say "foo2"; | |
say foo2(1); | |
say foo2(); | |
say "foo3"; | |
say foo3(1); | |
say foo3(); | |
say "foo4"; | |
say foo4(); | |
say foo4(False); | |
say foo4(False,False); | |
say foo4(False,False,False); | |
say foo4(True,False,False); | |
say foo4(False,True,False); | |
say foo4(False,True,True); | |
say foo4(True); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment