Skip to content

Commit

Permalink
Clarify the status of "skip"
Browse files Browse the repository at this point in the history
Also handle .skip(*) specifically and add more tests
  • Loading branch information
lizmat committed Jun 1, 2024
1 parent 4aa457e commit 8b86ed2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ rotor

**Status**: an optimized version of the [`.rotor`](https://docs.raku.org/type/List#routine_rotor) method has been implemented for the single argument non-`Pair` case. All other cases are basically too complicated to hyper, and therefore have no specific hypering logic.

skip
----

**Status**: the simple cases of `.skip()` and `.skip(N)` are handled by skipping that amount on the result iterator and returning the invocant.

The case of `.skip(*)` is handled by stopping any production of values and returning an empty `Seq`.

The nature of the other types of arguments on the [`.skip`](https://docs.raku.org/type/Seq#method_skip) method basically makes it impossible to hyper. Therefore, **no** specific hypering logic has been added for these cases.

slice
-----

Expand Down
14 changes: 14 additions & 0 deletions doc/ParaSeq.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@ has been implemented for the single argument non-C<Pair> case. All
other cases are basically too complicated to hyper, and therefore
have no specific hypering logic.

=head2 skip

B<Status>: the simple cases of C<.skip()> and C<.skip(N)> are
handled by skipping that amount on the result iterator and returning
the invocant.

The case of C<.skip(*)> is handled by stopping any production of
values and returning an empty C<Seq>.

The nature of the other types of arguments on the
L<C<.skip>|https://docs.raku.org/type/Seq#method_skip> method
basically makes it impossible to hyper. Therefore, B<no> specific
hypering logic has been added for these cases.

=head2 slice

B<Status>: the nature of the
Expand Down
4 changes: 4 additions & 0 deletions lib/ParaSeq.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,10 @@ class ParaSeq does Sequence {
self.iterator.skip-at-least($what);
self
}
multi method skip(ParaSeq:D: Whatever) {
self.stop;
self!pass-the-chain: Rakudo::Iterator.Empty
}
multi method skip(ParaSeq:D: |c) {
self!pass-the-chain: self.Seq.skip(|c).iterator
}
Expand Down
7 changes: 6 additions & 1 deletion t/06-skip.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6.*; # need v6.e semantics of .skip
use Test;
use ParaSeq;

plan 16;
plan 20;

my constant $elems = 200000;
my constant $batch = 16;
Expand All @@ -12,6 +12,7 @@ my constant $skip = @list.skip.List;
my constant $skip3 = @list.skip(3).List;
my constant $skipw3 = @list.skip(*-3).List;
my constant $skip34 = @list.skip(3,4).List;
my constant $skipW = @list.skip(*).List;

for 1, ParaSeq.default-degree {
my $seq := @list.&hyperize($batch, $_).skip;
Expand All @@ -29,6 +30,10 @@ for 1, ParaSeq.default-degree {
$seq := @list.&hyperize($batch, $_).skip(3,4);
isa-ok $seq, $_ == 1 ?? Seq !! ParaSeq;
is-deeply $seq.List, $skip34, "skip(3,4) with degree = $_";

$seq := @list.&hyperize($batch, $_).skip(*);
isa-ok $seq, $_ == 1 ?? Seq !! ParaSeq;
is-deeply $seq.List, $skipW, "skip(*) with degree = $_";
}

# vim: expandtab shiftwidth=4

0 comments on commit 8b86ed2

Please sign in to comment.