mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 20:34:44 +00:00
Merge branch 'main' into fix-#247
This commit is contained in:
commit
a373185dec
10 changed files with 62 additions and 25 deletions
|
@ -1,4 +1,8 @@
|
|||
class Array(list):
|
||||
def dedup(self):
|
||||
return Array(list(set(self)))
|
||||
def dedup_by(self, f):
|
||||
return Array(list(set(map(f, self))))
|
||||
def push(self, value):
|
||||
self.append(value)
|
||||
return self
|
||||
|
|
|
@ -8,3 +8,32 @@ class Str(str):
|
|||
return Str(s)
|
||||
else:
|
||||
return Error("Str can't be other than str")
|
||||
def get(self, i: int):
|
||||
if len(self) > i:
|
||||
return Str(self[i])
|
||||
else:
|
||||
return None
|
||||
|
||||
class StrMut(Str):
|
||||
def try_new(s: str):
|
||||
if isinstance(s, str):
|
||||
return StrMut(s)
|
||||
else:
|
||||
return Error("Str! can't be other than str")
|
||||
def clear(self):
|
||||
self = ""
|
||||
def pop(self):
|
||||
if len(self) > 0:
|
||||
last = self[-1]
|
||||
self = self[:-1]
|
||||
return last
|
||||
else:
|
||||
return Error("Can't pop from empty `Str!`")
|
||||
def push(self, c: str):
|
||||
self += c
|
||||
def remove(self, idx: int):
|
||||
char = self[idx]
|
||||
self = self[:idx] + self[idx+1:]
|
||||
return char
|
||||
def insert(self, idx: int, c: str):
|
||||
self = self[:idx] + c + self[idx:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue