Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revised Slip
Adds definitions, reflows. Actually, no need to prefix anything with
sub, so this closes #2683
  • Loading branch information
JJ committed Mar 21, 2019
1 parent ab74b86 commit 62c7f85
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions doc/Type/Slip.pod6
Expand Up @@ -6,17 +6,19 @@
class Slip is List {}
A C<Slip> is a L<List|/type/List> that automatically flatten into an outer List (or other
list-like container or iterable).
A C<Slip> is a L<List|/type/List> that automatically flattens into an outer List
(or other list-like container or iterable).
For example it allows you to write a L<map|/routine/map> that produces more than one value
into the result without nesting:
For example it allows you to write a L<map|/routine/map> that produces more than
one value into the result without nesting:
say <a b c>.map({ ($_, $_.uc).Slip }).join('|'); # OUTPUT: «a|A|b|B|c|C␤»
=for code
say <a b c>.map({ ($_, $_.uc).Slip }).join('|'); # OUTPUT: «a|A|b|B|c|C␤»
In contrast, when returning an ordinary List, the resulting list is nested:
say <a b c>.map({ $_, $_.uc }).join('|'); # OUTPUT: «a A|b B|c C␤»
=for code
say <a b c>.map({ $_, $_.uc }).join('|'); # OUTPUT: «a A|b B|c C␤»
To create a C<Slip>, either coerce another list-like type to it by calling the
C<Slip> method, or use the C<slip> subroutine:
Expand All @@ -27,19 +29,20 @@ C<Slip> method, or use the C<slip> subroutine:
}
A C<Slip> may also be created by using the C<prefix:<|>> operator. This differs
from the C<slip> subroutine in both precedence and treatment of single arguments.
In fact, C<prefix:<|>> only takes a single argument, so in that way, it behaves
closer to the C<.Slip> method than the C<slip> subroutine.
my $l = (1, 2, 3);
say (1, slip 2, 3).perl; # says (1, 2, 3) , slips 2, 3 into (1, …)
say (0, slip $l).perl; # says (0, $(1, 2, 3)), $l does not break apart
say (0, $l.Slip).perl; # says (0, 1, 2, 3) , slips from $l into (0, …)
say (|$l).perl; # says slip(1, 2, 3) , breaks apart $l
say (0, (|$l, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4)
say (0, ($l.Slip, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4)
say (0, (slip $l, 4), 5); # says (0 (1 2 3) 4 5), slips ($l, 4) into (0, …, 5)
say (0, ($l, 4).Slip, 5); # says (0 (1 2 3) 4 5), slips ($l, 4) into (0, …, 5)
from the C<slip> subroutine in both precedence and treatment of single
arguments. In fact, C<prefix:<|>> only takes a single argument, so in that way,
it behaves closer to the C<.Slip> method than the C<slip> subroutine.
=for code
my $l = (1, 2, 3);
say (1, slip 2, 3).perl; # says (1, 2, 3) , slips 2, 3 into (1, …)
say (0, slip $l).perl; # says (0, $(1, 2, 3)), $l does not break apart
say (0, $l.Slip).perl; # says (0, 1, 2, 3) , slips from $l into (0, …)
say (|$l).perl; # says slip(1, 2, 3) , breaks apart $l
say (0, (|$l, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4)
say (0, ($l.Slip, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4)
say (0, (slip $l, 4), 5); # says (0 (1 2 3) 4 5), slips ($l, 4) into (0, …, 5)
say (0, ($l, 4).Slip, 5); # says (0 (1 2 3) 4 5), slips ($l, 4) into (0, …, 5)
Loops that do not want to produce a value for an iteration use C<Slips>, rather
than empty C<List>s to do so, as do C<if> statements that do not run their
Expand All @@ -56,11 +59,25 @@ includes C<return> and C<take>.
=head1 Methods
=head2 method List
Defined as:
multi method List(Slip:D: --> List:D)
Turns it into a list.
=head2 sub slip
sub slip(*@ --> Slip:D)
Defined as:
multi sub slip(--> Empty)
multi sub slip(@args --> Slip:D)
multi sub slip(+args --> Slip:D)
Creates a L<Slip|/type/Slip> from its arguments.
Creates a L<Slip|/type/Slip> from its arguments by calling
L<C<.Slip>|/routine/Slip> on the object formed by them. Returns
L<C<Empty>|/type/Slip#index-entry-Empty-Empty> if called with void arguments.
=head1 Constants
Expand All @@ -74,4 +91,4 @@ C<Empty> is a C<Slip> of the empty C<List>.
=end pod


# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit 62c7f85

Please sign in to comment.