Skip to content

Commit be0a683

Browse files
authored
Rework List.join examples and description (#3570)
- Remove duplicate note about the optional separator for the method form - It's the subroutine form that is slurpy and flattening - Group related examples - Correct a typo
1 parent 8faec6b commit be0a683

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

doc/Type/List.pod6

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,28 +278,26 @@ Defined as:
278278
279279
Treats the elements of the list as strings by calling
280280
L<C<.Str>|/type/Any#routine_Str> on each of them, interleaves them with
281-
C<$separator> and concatenates everything into a single string. Note that you
282-
can omit the C<$separator> if you use the method syntax.
281+
C<$separator> and concatenates everything into a single string.
283282
284283
Example:
285284
286285
say join ', ', <a b c>; # OUTPUT: «a, b, c␤»
287286
288-
Note that the method form does not flatten sublists:
289-
290-
say (1, <a b c>).join('|'); # OUTPUT: «1|a b c␤»
291-
292287
The method form also allows you to omit the separator:
293288
294289
say <a b c>.join; # OUTPUT: «abc␤»
295290
296-
But it behaves slurpily, flattening all arguments after the first into a single
297-
list:
291+
Note that the method form does not flatten sublists:
292+
293+
say (1, <a b c>).join('|'); # OUTPUT: «1|a b c␤»
294+
295+
The subroutine form behaves slurpily, flattening all arguments after
296+
the first into a single list:
298297
299-
say join('|', 3, 'þ', 1+4i); # OUTPUT: «3|þ|1+4i␤»
300-
say join ', ', <a b c>, 'd', 'e' , 'f'; # OUTPUT: «a, b, c, d, e, f␤»
298+
say join '|', 1, <a b c>; # OUTPUT: «1|a|b|c␤»
301299
302-
In this case, the first list C«<a b c» is I<slurped> and flattened, unlike what
300+
In this case, the list C«<a b c>» is I<slurped> and flattened, unlike what
303301
happens when C<join> is invoked as a method.
304302
305303
If one of the elements of the list happens to be a C<Junction>, then C<join>

0 commit comments

Comments
 (0)