In Code§
See primary documentation in context for method assuming
method assuming(Callable : |primers)
Returns a new Callable
that has been primed with the arguments passed to assuming
. In other words, the new function implements the same behavior as the original, but has the values passed to .assuming
already bound to the corresponding parameters.
my sub slow();# takes only one parameter and as such wont forward $nsub bench();say .assuming(10000000).; # OUTPUT: «(10000000 7.5508834)»
For a sub with arity greater than one, you can use Whatever
*
for all of the positional parameters that are not "assumed".
sub first-and-last ( , )my = .assuming( *, 'Smith' );.( 'Joe' ); # OUTPUT: «Name is Joe Smith»
You can handle any combination of assumed and not assumed positional parameters:
sub longer-names ( , , , )my = .assuming( *, *, 'Public', * );.( 'Joe', 'Q.', 'Jr.'); # OUTPUT: «Name is Joe Q. Public Jr.»
Named parameters can be assumed as well:
sub foo.assuming(13, :42foo)(24, :72bar); # OUTPUT: «13 24 42 72»
And you can use .assuming
on all types of Callables, including Methods and Blocks:
# We use a Whatever star for the invocant:my = Str.^lookup('comb').assuming: *, /P \w+/;say comber 'Perl is awesome! Python is great! And PHP is OK too';# OUTPUT: «(Perl Python PHP)»my =.assuming: 'Raku';say learner :6months; # OUTPUT: «It took me 6 months to learn Raku»