Java Infinite Streams
blog.informatech.cr
blog.informatech.cr
One of the reasons why it's taken so long for Java to get these features was early arguments by members of the JCP that, quite literally, Java programmers were too scared off by the "complexity" of closures. Which is ironic because I see forum postings from Java programmers looking down on Javascript/Ruby and other scripting languages as for less-rigorous/serious engineers.
Soft bigotry of low expectations? How can Javascript programmers do fine with the complexity of closures (without types!), but Java programmers are a kind of special protected class of wimps that have to be shielded from functional programming of any sort? :)
Lambdas, Streams, and other high order constructs produce vastly more readable code and encourage additional re usability through more abstraction. If you think the introduction of "for-each" in Java5 was a good thing, why be opposed to collection.forEach((x) -> expr), if you can understand for(T x : collection) expr; ? Ditto for listener patterns, filters, comparators, runnables, futures, concurrency primitives, parallel streams, all are easier to use and understand with lambdas.
If takes only a few hours and one or two samples to get used to the new lambda syntax, especially if you are familiar with HOF in JS/Ruby/Python/Perl/C#/every-other-freakin-language.
The issue with closures and lambda syntax for java developers is probably around the fact that it is in most cases 100% unnecessary and doesn't really add anything to the product you're building. Even our core product which is c# is devoid of such things, not because we don't know about them but because we don't need them to drag stuff out of a database and throw it on a web page.
Just because closures and lambda functions are an awesome hammer, it doesn't mean every problem is a nail.
Since when did Java start sounding like, not Java? Is nullary a word? Lambda? Closure, isn't that a language? It's just stream management, why does it have to sound so complicated? Time to go back to C?
Edit: Looking at jebblue’s comment again, maybe I'm understanding him wrong and he’s serious after all. Poe’s law (http://en.wikipedia.org/wiki/Poe%27s_law) is in effect. In case “Closure, isn't that a language?” is serious, here’s the answer: no, but Clojure (http://clojure.org/) is. The name “Clojure” is a pun on “closure” (source: https://groups.google.com/d/msg/clojure/4uDxeOS8pwY/UHiYp7p1...).
If you can't get all the Java programmers to switch to a functional programming language, just add enough functional features to Java that you can do FP in it. It's genius, really.
Within another version or two, maybe Scala will be unnecessary.
Ruby is about as complex of a language as there is, the syntax and formal language spec are nothing short of baroque, but its flexibility and expressiveness allows you to write succinct, drop-dead simple code in it, that could only be expressed with pages of boilerplate in Java.
Adding functional features to Java will make its spec and implementation more complex, but it can make actual Java code less complex.
It's not all that complicated either, since it's basically what Unix pipes do: generate a stream of value, filter them, and consume a stream.
The article sure doesn't show a practical use, but rather enriches the standard library with useful features, and shows a pattern that can be applied to many practical problems.