Skip to content

Commit 4d14a8f

Browse files
authored
Document HyperWhatever
Closes #433
1 parent 42d00b5 commit 4d14a8f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

doc/Type/HyperWhatever.pod6

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=begin pod
2+
3+
=TITLE class HyperWhatever
4+
5+
=SUBTITLE Placeholder for multiple unspecified values/arguments
6+
7+
class HyperWhatever { }
8+
9+
C<HyperWhatever> is very similar in functionality to L<Whatever>. The
10+
difference lies in C<HyperWhatever> standing in for I<multiple> values, rather
11+
than a single one.
12+
13+
=head1 STANDALONE TERM
14+
15+
Just like with L<Whatever>, if a L<HyperWhatever> is used as a term on its own,
16+
no currying is done and the L<HyperWhatever> object will be used as-is:
17+
18+
sub foo ($arg) { say $arg.^name }
19+
foo **; # OUTPUT: «HyperWhatever␤»
20+
21+
You can choose to interpret such a value as standing for multiple values in
22+
your own routines. In core, a L<HyperWhatever> can be used with this meaning
23+
when smartmatching with L<Lists|/type/List>:
24+
25+
say (1, 8) ~~ (1, **, 8); # OUTPUT: «True␤»
26+
say (1, 2, 4, 5, 6, 7, 8) ~~ (1, **, 8); # OUTPUT: «True␤»
27+
say (1, 2, 8, 9) ~~ (1, **, 8); # OUTPUT: «False␤»
28+
29+
Wherever a L<HyperWhatever> appears in the list on the right-hand side means
30+
any number of elements can fill that space in the list being smartmatched.
31+
32+
=head1 CURRYING
33+
34+
When it comes to currying, the L<HyperWhatever> follows the same
35+
rules as L<Whatever>. The only difference is L<HyperWhatever> produces a
36+
L<Callable> with a L«C<*@> slurpy|/syntax/*@» as a signature:
37+
38+
say (**²)(1, 2, 3, 4, 5); # OUTPUT: «(1 4 9 16 25)␤»
39+
40+
A L<HyperWhatever> closure can be imagined as a
41+
L«C<Whatever> closure|/type/WhateverCode» with another sub wrapped around it
42+
that simply maps each element in the arguments over:
43+
44+
my &hyper-whatever = sub (*@args) { map *², @args }
45+
say hyper-whatever(1, 2, 3, 4, 5); # OUTPUT: «(1 4 9 16 25)␤»
46+
47+
When currying, mixing L<HyperWhatever> with L<Whatever> is not permitted.
48+
49+
=end pod
50+
51+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)