|
|
|
|
|
by diek
3859 days ago
|
|
Using the Java 8 'stream' API: IntStream.iterate(0, i -> i + 1)
.mapToObj( i -> Collections.nCopies(i, i % 2 == 0) )
.flatMap(Collection::stream)
.limit(1000)
Generate an infinite series of incrementing numbers, starting from 0, map each to a stream of boolean indicating true/false, flatten that stream of streams, then limit the output. |
|
Yeah, I'd still argue that the clojure stream api is more readable though ;).
The thing is that these additions slowly creep into java, which is great. But you still have to wait for the mercy of the language designers.Clojure is so flexible that it is possible to bring these things in as libraries, resulting in a very lightweight and stable core, and a very rapidly evolving ecosystem.
Also the persistent data-structures of Clojure make life so much easier. It's basically a language build around persistent maps and arrays.