mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 13:41:10 +00:00
feat: add Array.update_nth!
This commit is contained in:
parent
07e37c878c
commit
74bca70017
7 changed files with 87 additions and 15 deletions
|
@ -94,3 +94,12 @@ array = pyimport "Array"
|
|||
assert arr == [3, 4]
|
||||
'''
|
||||
strict_map!: |T, N: Nat|(self: Array!(T, N), f: T -> T) => NoneType
|
||||
'''
|
||||
Update `index`-th element of the array according to the passed function `f`.
|
||||
'''
|
||||
'''erg
|
||||
arr = ![1, 2]
|
||||
arr.udpate_nth! 0, x -> x + 1
|
||||
assert arr == [2, 2]
|
||||
'''
|
||||
update_nth!: |T, N: Nat|(self: Array!(T, N), index: Nat, f: T -> T) => NoneType
|
||||
|
|
|
@ -69,3 +69,6 @@ class Array(list):
|
|||
if not contains_operator(elem_t, elem):
|
||||
return False
|
||||
return True
|
||||
|
||||
def update_nth(self, index, f):
|
||||
self[index] = f(self[index])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue