Вопрос

Io allows an optional parameter referring to the index of a list item. How do I use that to refer to the list being mapped, for example, I could write:

testList := list(1,2,3,4)
testList map(i,v, if(testList(i+v), v, v-1))

and the result would be list(1,2,3,3)

But what if I want to write that without creating the variable testList? How do I refer to the list that I'm mapping?

Это было полезно?

Решение

Without using an intermediate name, you cannot access the receiver inside the map. The map is evaluated within the context of the caller, i.e., where your call to list(1,2,3,4) would be made.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top