Can the JVM optimize this code
How does this code get optimized in the Java compiler or JVM, I am asking specifically for optimization done if this such code was written java
Stream.of(1, 2, 3)
.map(i -> i + 1)
.map(i -> i + 1)
.map(i -> i + 1);
to something like
Stream.of(1, 2, 3)
.map(i -> i + 3)
or be even more aggressive and replace this with a basic for loop which could possible improve performance.
In clojure there is a concept of transducer which is a sort of optimization that you can do to compose reduce-able functions into a single function and remove the overhead of lazy propagation. Can the JVM transduce some functions in a fluent api?
for instance if we had a decorator interface for Java streams
decor-map(decor-map(base-map (i -> i + 1), i -> i +1), i -> i + 1)
then I assume that the compile could somehow try to transduce the decorator maps. But how is this possible in a fluent api?