Since Groovy 2.4.0 there is a withIndex()
method which gets added to java.lang.Iterable
.
So, in a functional fashion (no side effect, immutable), it looks like
def myList = [
[position: 0, name: 'Bob'],
[position: 0, name: 'John'],
[position: 0, name: 'Alex'],
]
def result = myList.withIndex().collect { element, index ->
[position: index, name: element["name"]]
}