feat: support Array, Str, Bytes slice

This commit is contained in:
Shunsuke Shibayama 2023-07-15 12:29:07 +09:00
parent 579615d76e
commit 0152e368ab
14 changed files with 170 additions and 19 deletions

View file

@ -12,6 +12,13 @@ class Range:
def __contains__(self, item):
pass
@staticmethod
def from_slice(slice):
pass
def into_slice(self):
pass
def __getitem__(self, item):
res = self.start + item
if res in self:
@ -56,6 +63,13 @@ class RightOpenRange(Range):
def __contains__(self, item):
return self.start <= item < self.end
@staticmethod
def from_slice(slice):
return Range(slice.start, slice.stop)
def into_slice(self):
return slice(self.start, self.end)
# represents `start<..<end`
class OpenRange(Range):
@ -68,6 +82,13 @@ class ClosedRange(Range):
def __contains__(self, item):
return self.start <= item <= self.end
@staticmethod
def from_slice(slice):
return Range(slice.start, slice.stop - 1)
def into_slice(self):
return slice(self.start, self.end + 1)
class RangeIterator:
def __init__(self, rng):