Functional programming in Java
dzone.com
dzone.com
So for example, Pratik's first example (iterate through a Collection of Strings and return the elements starting with "inv") would be written like:
List<String> list = Arrays.asList("invalid1", " invalid2");
return new FilteredIterator(list.iterator(),new UnaryFunctor() { boolean test(String str) { return str.startsWith("inv"); });
although as a practical matter most users would have predefined constant functions, predicates, and helpers, so the second line would read more like: return F.filter(list.iterator(),F.startsWith("inv"));
(Yes, Java is verbose.)It's actually a pretty well tested (100% coverage) and documented library that I used on a number of personal and work projects. but never bothered to push it out of the commons "sandbox". You can find it at http://commons.apache.org/sandbox/functor/. The examples (http://commons.apache.org/sandbox/functor/examples.html) are kind of fun. We were experimenting with a test-first, pseudo-literate programming documentation style.