<<FOR i: 1..elements.size>>
<<elements.get(i - 1).method(i)>>
<<ENDFOR>>
I've realized it with plain xtend2 and it works like a charm for me:@Data public class ListItem<T>
{
T value
int index
boolean isFirst
boolean isLast
}def <T> indexed(Iterable<T> list)
{
var List<ListItem<T>> result = newArrayList
val lastIndex = list.size - 1
var currentIndex = 0
for (item : list)
{
result += new ListItem<T>(
item,
currentIndex,
currentIndex == 0,
currentIndex == lastIndex
)
}
return result
}Usage:«FOREACH it : values.indexed»
«value.method(index)»
«ENDFOREACH-»Especially in combination with the "it" feature it is quite as easy to use as the old xpand solution - and it is extendible as well.