feat: add Array.update_nth!

This commit is contained in:
Shunsuke Shibayama 2023-08-28 15:33:58 +09:00
parent 07e37c878c
commit 74bca70017
7 changed files with 87 additions and 15 deletions

View file

@ -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

View file

@ -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])