Funktion nur auf ein Element in Liste oder Array in Scala anwenden
Für eine bestimmte Liste oder ein Array, zum Beispiel
val list = (1 to 3).toList
val array = (1 to 3).toArray
und eine gegebene Funktion, die von und auf den Sammlungstyp abgebildet wird, zum Beispiel
def f(v: Int): Int = v + 10
wie bewerbe ich michf
zum i-ten Element vonlist
oderarray
dami
list.myApply(f, ith = 2)
res: List(1,12,3)
und auc
array.myApply(f, ith = 2)
res: Array(1,12,3)