Created
July 7, 2020 09:28
-
-
Save lizmat/ab20653dfb09856707a45b1575768d31 to your computer and use it in GitHub Desktop.
Minimal Seq.AT-POS attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core.c/Seq.pm6 b/src/core.c/Seq.pm6 | |
index 8b06b1628..f9d5f1643 100644 | |
--- a/src/core.c/Seq.pm6 | |
+++ b/src/core.c/Seq.pm6 | |
@@ -5,6 +5,9 @@ my class Seq is Cool does Iterable does Sequence { | |
# way through. Can only be obtained once. | |
has Iterator $!iter; | |
+ # The number of values that have been produced | |
+ has int $!produced; | |
+ | |
# The only valid way to create a Seq directly is by giving it the | |
# iterator it will consume and maybe memoize. | |
multi method new(Seq: Iterator:D $iter) { | |
@@ -41,6 +44,20 @@ my class Seq is Cool does Iterable does Sequence { | |
) | |
} | |
+ proto method AT-POS(|) {*} | |
+ multi method AT-POS(int $pos) is raw { | |
+ if $pos < $!produced { | |
+ die "asked $pos, which was already produced"; | |
+ } | |
+ else { | |
+ my int $skip = $pos - $!produced; | |
+ $!produced = $pos; | |
+ $!iter.skip($skip) | |
+ ?? $!iter.pull-one | |
+ !! Nil | |
+ } | |
+ } | |
+ | |
multi method Seq(Seq:D:) { self } | |
method Capture() { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment