If we can't have closures, can we at least have comprehensions?
Dear Sun,
If we can't have closures in Java 7, can we at least have comprehensions added to the collections API? It seems I'm forever writing, or pulling in Commons Collections (which lacks generics) or Functional Java to add simple functional list comprehension support to my projects, if the core Java collections API included something as simple as:
public static interface Collector{ boolean collect(T t); } public static List collect(List list, Collector map) { List mappedList = new ArrayList (); for (T t : list) { if (map.collect(t)) { mappedList.add(t); } } return mappedList; }
and several others, then we'd be able to introduce a new standard programming model to Java developers, and practically show them how and why adding closures would benefit them.
Of course, we just just promote the hell out of Functional Java and be done with it :)
Comments (4)
You can always use commons-collections with generics (http://sourceforge.net/projects/collections).
no, we can't. go clean up your room.
heh...I was looking for exactly that a few weeks ago, after working with FileFilter
And there was I assuming you meant Python style List Comprehensions, as implemened for Java in the Kijaro project - http://kijaro.dev.java.net