Commit
This is a temporary partial commit. If you see it on master then things went very wrong.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,33 @@ my class Seq is Cool does Iterable does Sequence { | |
) | ||
} | ||
|
||
proto method AT-POS(|) {*} | ||
multi method AT-POS(Seq:D: Int:D $idx) is raw { | ||
if $idx < $!produced { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AlexDaniel
Author
Contributor
|
||
die "asked $idx, which was already produced"; | ||
} | ||
else { | ||
my int $skip = $idx - $!produced; | ||
$!produced = $idx; | ||
$!iter.skip($skip) | ||
?? $!iter.pull-one | ||
!! Nil | ||
} | ||
} | ||
|
||
multi method AT-POS(Seq:D: int $idx) is raw { | ||
if $idx < $!produced { | ||
die "asked $idx, which was already produced"; | ||
} | ||
else { | ||
my int $skip = $idx - $!produced; | ||
$!produced = $idx; | ||
$!iter.skip($skip) | ||
?? $!iter.pull-one | ||
!! Nil | ||
} | ||
} | ||
|
||
multi method Seq(Seq:D:) { self } | ||
|
||
method Capture() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,13 +57,13 @@ my role Sequence does PositionalBindFailover { | |
|
||
method Numeric(::?CLASS:D:) { self.cache.elems } | ||
|
||
multi method AT-POS(::?CLASS:D: Int:D $idx) is raw { | ||
self.cache.AT-POS($idx) | ||
} | ||
#multi method AT-POS(::?CLASS:D: Int:D $idx) is raw { | ||
This comment has been minimized.
Sorry, something went wrong.
lizmat
Contributor
|
||
# self.cache.AT-POS($idx) | ||
#} | ||
|
||
multi method AT-POS(::?CLASS:D: int $idx) is raw { | ||
self.cache.AT-POS($idx) | ||
} | ||
#multi method AT-POS(::?CLASS:D: int $idx) is raw { | ||
# self.cache.AT-POS($idx) | ||
#} | ||
|
||
multi method EXISTS-POS(::?CLASS:D: Int:D $idx) { | ||
self.cache.EXISTS-POS($idx) | ||
|
3 comments
on commit c9a4f07
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.raku.org/type/Sequence documents it providing AT-POS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And don't forget roast :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roast is a later step. Of course the spec expects Seq to behave a certain way, I'm proposing to change the spec.
I think this will mean that
some-seq[@foo]
will only work if@foo
is ordered? Even accepting that restriction,some-seq[* - 2]
, which wants theelems
(and so much produce everything), is going to be problematic with this too. I dunno if a more fruitful direction would be aSequence
overload on thepostcircumfix
candidates...