It is common to have two or more functions/methods combined and work as a whole. For examples:
To "combine" functions in javascript in a functional way?
Is it possible in C++11 to combine functions into a new function?
However, I was wondering if something like this can be done:
Function<Integer, Integer> f = x -> x + 1;
Function<Integer, Integer> g = x -> x * 2;
Function<Integer, Integer> h = f.compose(g);
** **
h.toString //get x-> x*2+1 , what I want
The functions are "deeply" combined, which is similar to the simplification of expressions in mathematical software like Matlab.
I know there are some useful techniques in compilaters and I am seeking how it can be done in high-level languages.
By the way, I guess it is theoretically possible using JVM bytecode manipulation but that would be too complex.