Type-based dispatch
Type constraints in signature used to select sub:
multi sub double(Num $x) { return 2 * $x; } multi sub double(Str $x) { return "$x $x"; } say double(21); # 42 say double("Hello"); # Hello Hello
Perl 6 | Perl 6 today | #66 |
Type constraints in signature used to select sub:
multi sub double(Num $x) { return 2 * $x; } multi sub double(Str $x) { return "$x $x"; } say double(21); # 42 say double("Hello"); # Hello Hello
Copyright © 2009 http://www.pmichaud.com/2009/pres/ |