I am trying to apply “transform” to List <Map <String, String>>. Is it possible in the “Function.apply” method to get the index of the current item in the List?
Lists.transform(data, new Function<Map<String, String>, Map<String, String>>() {
private static int index = 0;
@Override
public Map<String, String> apply(Map<String, String> from) {
from.put(key, value); // need to get index
return from;
}
});
Often in Java, using a loop is much simpler and cleaner.
I should say that I am in favour of functional programming in a language which supports it. Java 7 is not well suited for functional programming and sometimes you have to resort to iteration. Java 8 and 9 promises to be more functional programming friendly with the addition of closures.
IMHO Java doesn’t even support recursion as well as many languages do. A lack of tail call elimination in the JVM is a deficiency.