mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
feat: add {Str, List}.from
This commit is contained in:
parent
65d05cb37b
commit
96f4c1cf98
10 changed files with 56 additions and 5 deletions
|
@ -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, _)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue