feat: add {Str, List}.from

This commit is contained in:
Shunsuke Shibayama 2024-04-30 18:44:31 +09:00
parent 65d05cb37b
commit 96f4c1cf98
10 changed files with 56 additions and 5 deletions

View file

@ -56,3 +56,10 @@
assert [1, 2, 3].reversed() == [3, 2, 1]
'''
reversed: |T: Type, N: Nat|(self: List(T, N)) -> List(T, N)
'''
Returns the array with the first `nth` elements removed.
'''
'''erg
assert [1, 2, 3, 4, 5].from(2) == [3, 4, 5]
'''
from: |T: Type|(self: List(T, _), nth: Nat) -> List(T, _)

View file

@ -181,3 +181,10 @@
translate: (self: .Str, table: {Nat: Nat or NoneType}) -> .Str
upper: (self: .Str) -> .Str
zfill: (self: .Str, width: Nat) -> .Str
'''
Returns the substring of the string starting at the given index.
'''
'''erg
assert "abcde".from(2) == "cde"
'''
from: (self: Str, nth: Nat) -> Str

View file

@ -137,6 +137,8 @@ class List(list):
new.extend(deepcopy(self))
return List(new)
def from_(self, nth: int):
return self[nth:]
class UnsizedList:
elem: object

View file

@ -48,6 +48,8 @@ class Str(str):
else:
return str.__getitem__(self, index_or_slice)
def from_(self, nth: int):
return self[nth:]
class StrMut(MutType): # Inherits Str
value: Str

View file

@ -65,8 +65,8 @@
.Islice(T) <: Output T
.Islice(T) <: Iterable T
.Islice(T).
__call__: (iterable: Iterable(T), start := Int, stop := Int, step := Int) -> .Islice(T)
.islice: |T|(iterable: Iterable(T), start := Int, stop := Int, step := Int) -> .Islice(T)
__call__: (iterable: Iterable(T), start := Int or NoneType, stop := Int or NoneType, step := Int or NoneType) -> .Islice(T)
.islice: |T|(iterable: Iterable(T), start := Int or NoneType, stop := Int or NoneType, step := Int or NoneType) -> .Islice(T)
.Pairwise = 'pairwise': (T: Type) -> ClassType
.Pairwise(T) <: Output T