mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
feat: support Array
, Str
, Bytes
slice
This commit is contained in:
parent
579615d76e
commit
0152e368ab
14 changed files with 170 additions and 19 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue