mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
Add some builtin types methods
This commit is contained in:
parent
c97b8d61ad
commit
c44355346e
4 changed files with 160 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
from _erg_nat import Nat
|
||||
from _erg_nat import NatMut
|
||||
from _erg_result import Error
|
||||
|
||||
class Bool(Nat):
|
||||
|
@ -15,3 +16,27 @@ class Bool(Nat):
|
|||
return "False"
|
||||
def __repr__(self) -> str:
|
||||
return self.__str__()
|
||||
def mutate(self):
|
||||
return BoolMut(self)
|
||||
def invert(self):
|
||||
return Bool(not self)
|
||||
|
||||
class BoolMut(NatMut):
|
||||
value: Bool
|
||||
|
||||
def __init__(self, b: Bool):
|
||||
self.value = b
|
||||
def __repr__(self):
|
||||
return self.value.__repr__()
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, bool):
|
||||
return self.value == other
|
||||
else:
|
||||
return self.value == other.value
|
||||
def __ne__(self, other):
|
||||
if isinstance(other, bool):
|
||||
return self.value != other
|
||||
else:
|
||||
return self.value != other.value
|
||||
def invert(self):
|
||||
self.value = self.value.invert()
|
||||
|
|
|
@ -19,6 +19,8 @@ class Str(str):
|
|||
return StrMut(self)
|
||||
def to_int(self):
|
||||
return Int(self) if self.isdigit() else None
|
||||
def contains(self, s):
|
||||
return s in self
|
||||
def __add__(self, other):
|
||||
return then__(str.__add__(self, other), Str)
|
||||
def __radd__(self, other):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue