@@ -1200,7 +1200,7 @@ Routines that manipulate arrays and other containers.
1200
1200
1201
1201
Defined as:
1202
1202
1203
- multi sub pop(@container)
1203
+ multi sub pop(@container) is raw
1204
1204
1205
1205
Calls method C < pop > on the C < Positional > container. That method is supposed to
1206
1206
remove and return the last element, or return a L < C < Failure > |/type/Failure> if
@@ -1213,7 +1213,7 @@ for an example.
1213
1213
1214
1214
Defined as:
1215
1215
1216
- multi sub shift(@container)
1216
+ multi sub shift(@container) is raw
1217
1217
1218
1218
Calls method C < shift > on the C < Positional > container. That method, on
1219
1219
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]»
1234
1234
Defined as:
1235
1235
1236
1236
multi sub push(\container, **@values is raw)
1237
+ multi sub push(\container, \arg)
1237
1238
1238
1239
Calls method C < push > on the container, which is supposed to add the provided
1239
1240
values to the end of the container or parts thereof. See the documentation of
1240
1241
the L < C < Hash > method|/routine/push#(Hash)_method_push> for an example where
1241
1242
indirection via this subroutine can be helpful.
1242
1243
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
+
1243
1257
= head2 sub append
1244
1258
1245
1259
Defined as:
1246
1260
1247
- multi sub append(\container, +values)
1261
+ multi sub append(\container, **@values is raw)
1262
+ multi sub append(\container, \arg)
1248
1263
1249
1264
Calls method C < append > on the container, which is supposed to add the provided
1250
1265
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)
1254
1277
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
1257
1280
silently ignore literal pairs that are interpreted as named arguments, the
1258
1281
subroutine will throw:
1259
1282
0 commit comments