Add Str <-> Int, Nat convertors

This commit is contained in:
Shunsuke Shibayama 2022-12-06 23:44:24 +09:00
parent 592a77caab
commit 287a65276e
6 changed files with 63 additions and 4 deletions

View file

@ -1,4 +1,5 @@
from _erg_result import Error
from _erg_int import Int
class Str(str):
def __instancecheck__(cls, obj):
@ -15,6 +16,8 @@ class Str(str):
return None
def mutate(self):
return StrMut(self)
def to_int(self):
return Int(self) if self.isdigit() else None
class StrMut(): # Inherits Str
value: Str