Skip to content

Commit 6686dfe

Browse files
dumarchieJJ
authored andcommitted
Restore documentation of multis
All multi signatures found in the Rakudo implementation should be documented. Parameter names can be changed to fit the documentation.
1 parent 2d3d50c commit 6686dfe

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

doc/Type/Array.pod6

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ L<subroutine|/language/independent-routines#sub_pop>. For example:
5555
Defined as:
5656
5757
multi method push(Array:D: **@values is raw --> Array:D)
58+
multi method push(Array:D: \value --> Array:D)
59+
multi method push(Array:D: Slip \values --> Array:D)
5860
59-
Adds the provided values to the end of the array, and returns the modified
60-
array. If any argument is a C<Slip>, method C<push> will add the values
61+
Adds the provided value or values to the end of the array, and returns the
62+
modified array. If any argument is a C<Slip>, method C<push> will add the values
6163
produced by the argument's L<iterator|/routine/iterator>. It throws if the
6264
invocant array or a C<Slip> L<is lazy|/routine/is-lazy>.
6365
@@ -91,15 +93,23 @@ values that are produced by a single non-slipping C<Iterable>.
9193
9294
Defined as
9395
96+
multi method append(Array:D: **@values is raw --> Array:D)
97+
multi method append(Array:D: \arg --> Array:D)
98+
99+
Adds the provided values to the end of the array and returns the modified array,
100+
or throws if the invocant array or an argument that requires flattening L<is
101+
lazy|/routine/is-lazy>.
102+
103+
In contrast with L<method push|/type/Array#method_push>, method C<append>
104+
adheres to the L<single argument rule|/language/functions#Slurpy_conventions>
105+
and is probably best thought of as:
106+
94107
multi method append(Array:D: +values --> Array:D)
95108
96-
Adds the provided values to the end of the array and returns the modified
97-
array, or throws if the invocant array or an argument that requires flattening
98-
L<is lazy|/routine/is-lazy>.
109+
This means that if you pass a B<single> argument that is a
110+
non-L<itemized|/language/mop#VAR> C<Iterable>, C<append> will try to flatten it.
99111
100-
The difference with L<method push|/type/Array#method_push> is that if you append
101-
a B<single> non-L<itemized|/language/mop#VAR> C<Iterable>, C<append> will try to
102-
flatten it. For example:
112+
For example:
103113
104114
my @a = <a b c>;
105115
my @b = <d e f>;

doc/Type/independent-routines.pod6

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ Routines that manipulate arrays and other containers.
12001200
12011201
Defined as:
12021202
1203-
multi sub pop(@container)
1203+
multi sub pop(@container) is raw
12041204
12051205
Calls method C<pop> on the C<Positional> container. That method is supposed to
12061206
remove and return the last element, or return a L<C<Failure>|/type/Failure> if
@@ -1213,7 +1213,7 @@ for an example.
12131213
12141214
Defined as:
12151215
1216-
multi sub shift(@container)
1216+
multi sub shift(@container) is raw
12171217
12181218
Calls method C<shift> on the C<Positional> container. That method, on
12191219
a mutable container that actually implements it (such as an
@@ -1234,26 +1234,49 @@ say shift @a; # ERROR: «Cannot shift from an empty Array[Int]␤»
12341234
Defined as:
12351235
12361236
multi sub push(\container, **@values is raw)
1237+
multi sub push(\container, \arg)
12371238
12381239
Calls method C<push> on the container, which is supposed to add the provided
12391240
values to the end of the container or parts thereof. See the documentation of
12401241
the L<C<Hash> method|/routine/push#(Hash)_method_push> for an example where
12411242
indirection via this subroutine can be helpful.
12421243
1244+
The C<push> method of the container is supposed to flatten all arguments of type
1245+
C<Slip>. Therefore, if you want to implement a conforming method for a new
1246+
container type, it should behave as if its signature was just:
1247+
1248+
multi method push(::?CLASS:D: **@values --> ::?CLASS:D)
1249+
1250+
Autovivification to an instance of the new type is L<provided by the default
1251+
base class|/routine/append#(Any)_method_append> if the new type implements the
1252+
C<Positional> role. If the new type is not C<Positional>, autovivification can
1253+
be implemented by an additional multi method with a signature like
1254+
1255+
multi method push(::?CLASS:U: **@values --> ::?CLASS:D)
1256+
12431257
=head2 sub append
12441258
12451259
Defined as:
12461260
1247-
multi sub append(\container, +values)
1261+
multi sub append(\container, **@values is raw)
1262+
multi sub append(\container, \arg)
12481263
12491264
Calls method C<append> on the container, which is supposed to add the provided
12501265
values to the end of the container or parts thereof. Unlike method C<push>,
1251-
method C<append> is supposed to add the values produced by the argument's
1252-
L<iterator|/routine/iterator> if called with a B<single> non-slipping
1253-
C<Iterable> that is not inside a C<Scalar> container.
1266+
method C<append> should follow the L<single argument
1267+
rule|/language/functions#Slurpy_conventions>. So if you want to implement a
1268+
conforming method C<append> for a new container type, it should behave as if its
1269+
signature was just:
1270+
1271+
multi method append(::?CLASS:D: +values --> ::?CLASS:D)
1272+
1273+
Similar to L<routine C<push>|/routine/push#(Independent_routines)_sub_push>, you
1274+
may need to add a multi method if you want to support autovivification:
1275+
1276+
multi method append(::?CLASS:U: +values --> ::?CLASS:D)
12541277
1255-
Indirection via this subroutine can be helpful when appending to the values of a
1256-
C<Hash>. Whereas L<method C<append>|/routine/append#(Hash)_method_append> will
1278+
The subroutine form of C<append> can be helpful when appending to the values of
1279+
a C<Hash>. Whereas L<method C<append>|/routine/append#(Hash)_method_append> will
12571280
silently ignore literal pairs that are interpreted as named arguments, the
12581281
subroutine will throw:
12591282

0 commit comments

Comments
 (0)