Skip to content

Commit

Permalink
Added multi-positional use of assuming (#1296)
Browse files Browse the repository at this point in the history
Borrowed content from brian d foy's Stack Overflow post http://stackoverflow.com/a/43669837/215487
  • Loading branch information
molecules authored and zoffixznet committed May 5, 2017
1 parent cc1b62a commit 1f7cc4e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doc/Type/Callable.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ corresponding parameters.
say &slow.assuming(10000000).&bench; # OUTPUT: «(10000000 7.5508834)␤»
For a sub with arity greater than one, you can use C<Whatever> C<*> for all of the positional parameters that are not "assumed".
sub first-and-last ( $first, $last ) {
say "Name is $first $last";
}
my &surnamed-smith = &first-and-last.assuming( *, 'Smith' );
&surnamed-smith.( 'Joe' ); # OUTPUT: «Name is Joe Smith␤»
You can handle any combination of assumed and not assumed positional parameters:
sub longer-names ( $first, $middle, $last, $suffix ) {
say "Name is $first $middle $last $suffix";
}
my &surnamed-public = &longer-names.assuming( *, *, 'Public', * );
&surnamed-public.( 'Joe', 'Q.', 'Jr.'); # OUTPUT: «Name is Joe Q. Public Jr.␤»
(Multi-parameter examples adapted from brian d foy's post http://stackoverflow.com/a/43669837/215487)
=comment according to design docs it's Callable but in rakudo it's assuming is in Block
=head1 Operators
Expand Down

0 comments on commit 1f7cc4e

Please sign in to comment.