Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top