Skip to content

Commit a7ed560

Browse files
committed
Flesh out Slip with examples, and fix a typo
1 parent 4884eb7 commit a7ed560

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

doc/Type/Slip.pod

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,37 @@ into the result without nesting:
1414
1515
say <a b c>.map({ ($_, $_.uc).Slip }).join('|'); # a|A|b|B|c|C
1616
17-
In contrast, when returning an oridinar List, the resulting list is nested:
17+
In contrast, when returning an ordinary List, the resulting list is nested:
1818
1919
say <a b c>.map({ $_, $_.uc }).join('|'); # a A|b B|c C
2020
2121
To create a C<Slip>, either coerce another list-like type to it by calling the
2222
C<Slip> method, or use the C<slip> subroutine:
2323
24+
# This says "1" and then says "2", rather than saying "(1 2)"
2425
.say for gather {
2526
take slip(1, 2);
2627
}
2728
29+
A C<Slip> may also be created by using the C<prefix:<|>> operator. This differs
30+
from the C<slip> subroutine in both precedence and treatment of single arguments.
31+
In fact, C<prefix:<|>> only takes a single argment, so it that way, it behaves
32+
closer to the C<.Slip> method than the C<slip> subroutine.
33+
34+
my $l = (1,2,3);
35+
say (1, slip 2,3).perl; # says (1,2,3) , slips 2,3 into (1, …)
36+
say (0, slip $l).perl; # says (0,$(1,2,3)) , $l does not break apart
37+
say (0, $l.Slip).perl; # says (0,1,2,3) , slips from $l into (0, …)
38+
say (|$l).perl; # says slip(1,2,3) , breaks apart $l
39+
say (0, (|$l, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4)
40+
say (0, ($l.Slip, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4)
41+
say (0, (slip $l, 4), 5); # says (0 (1 2 3) 4 5), slips ($l,4) into (0, …, 5)
42+
say (0, ($l, 4).Slip, 5); # says (0 (1 2 3) 4 5), slips ($l,4) into (0, …, 5)
43+
44+
Loops that do not want to produce a value for an iteration use C<Slips>, rather
45+
than empty C<List>s to do so, as do C<if> statements that do not run their
46+
blocks.
47+
2848
=head1 Methods
2949
3050
=head2 sub slip

0 commit comments

Comments
 (0)