class HyperWhatever
Placeholder for multiple unspecified values/arguments
1 | Standalone term |
2 | Currying |
3 | Type Graph |
HyperWhatever
is very similar in functionality to Whatever. The difference lies in HyperWhatever
standing in for multiple values, rather than a single one.
Standalone term
Just like with Whatever, if a HyperWhatever is used as a term on its own, no currying is done and the HyperWhatever object will be used as-is:
sub foo ()foo **; # OUTPUT: «HyperWhatever»
You can choose to interpret such a value as standing for multiple values in your own routines. In core, a HyperWhatever can be used with this meaning when smartmatching with Lists:
say (1, 8) ~~ (1, **, 8); # OUTPUT: «True»say (1, 2, 4, 5, 6, 7, 8) ~~ (1, **, 8); # OUTPUT: «True»say (1, 2, 8, 9) ~~ (1, **, 8); # OUTPUT: «False»
Wherever a HyperWhatever appears in the list on the right-hand side means any number of elements can fill that space in the list being smartmatched.
Currying
When it comes to currying, the HyperWhatever follows the same rules as Whatever. The only difference is HyperWhatever produces a Callable with a *@
slurpy as a signature:
say (**²)(1, 2, 3, 4, 5); # OUTPUT: «(1 4 9 16 25)»
A HyperWhatever closure can be imagined as a Whatever
closure with another sub wrapped around it that simply maps each element in the arguments over:
my = sub (*)say hyper-whatever(1, 2, 3, 4, 5); # OUTPUT: «(1 4 9 16 25)»
When currying, mixing HyperWhatever with Whatever is not permitted.