我一直在玩 Pony 数组以更好地理解 Pony,并想为任何数组编写 map 函数。
我说的是当今大多数语言用于转换集合元素的标准 map 函数之类的东西,例如在 Clojure 中:
(map #(+ 1 %) [1 2 3]) ; => [2 3 4]
但我希望它实际修改给定的数组,而不是返回一个新数组。
到目前为止,由于功能,我目前的尝试遇到了许多错误:
// array is "iso" so I can give it to another actor and change it
let my_array: Array[U64] iso = [1; 2; 3; 4]
// other actor tries to recover arrays as "box" just to call pairs() on it
let a = recover box my_array end // ERROR: can't recover to this capability
for (i, item) in a.pairs() do
// TODO set item at i to some other mapped value
try my_array.update(i, fun(item))? end
end
任何人都知道如何做到这一点