erg/compiler/erg_compiler/lib/std/_erg_nat.py
Shunsuke Shibayama 111a9f5615 Fix #247
2022-11-27 20:24:11 +09:00

18 lines
394 B
Python

from _erg_result import Error
class Nat(int):
def try_new(i): # -> Result[Nat]
if i >= 0:
return Nat(i)
else:
return Error("Nat can't be negative")
def times(self, f):
for _ in range(self):
f()
def saturating_sub(self, other):
if self > other:
return self - other
else:
return 0