

Functional programming in Java - mariofusco
http://www.dzone.com/links/r/functional_programming_in_java_using_lambdaj.html

======
spokey
If you'll indulge me in some nostalgia, quite some time ago I wrote a similar
Apache Commons (it was Jakarta Commons at the time) library called "functor",
essential trying to solve the problem of functions-as-first-class-objects-are-
missing-in-Java (but without resorting to byte code manipulation or anything
fancy like that; I may not have been clever enough for that). This was just
prior to the introduction of generics into the core language, if memory
serves.

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.

