Skip to content

Commit 1f7cc4e

Browse files
moleculeszoffixznet
authored andcommitted
Added multi-positional use of assuming (#1296)
Borrowed content from brian d foy's Stack Overflow post http://stackoverflow.com/a/43669837/215487
1 parent cc1b62a commit 1f7cc4e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/Type/Callable.pod6

+22
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ corresponding parameters.
5555
5656
say &slow.assuming(10000000).&bench; # OUTPUT: «(10000000 7.5508834)␤»
5757
58+
For a sub with arity greater than one, you can use C<Whatever> C<*> for all of the positional parameters that are not "assumed".
59+
60+
sub first-and-last ( $first, $last ) {
61+
say "Name is $first $last";
62+
}
63+
64+
my &surnamed-smith = &first-and-last.assuming( *, 'Smith' );
65+
66+
&surnamed-smith.( 'Joe' ); # OUTPUT: «Name is Joe Smith␤»
67+
68+
You can handle any combination of assumed and not assumed positional parameters:
69+
70+
sub longer-names ( $first, $middle, $last, $suffix ) {
71+
say "Name is $first $middle $last $suffix";
72+
}
73+
74+
my &surnamed-public = &longer-names.assuming( *, *, 'Public', * );
75+
76+
&surnamed-public.( 'Joe', 'Q.', 'Jr.'); # OUTPUT: «Name is Joe Q. Public Jr.␤»
77+
78+
(Multi-parameter examples adapted from brian d foy's post http://stackoverflow.com/a/43669837/215487)
79+
5880
=comment according to design docs it's Callable but in rakudo it's assuming is in Block
5981
6082
=head1 Operators

0 commit comments

Comments
 (0)