reason that handler execute in invert order in ring wrapper
(Rugal Bernstein), pre-around, pre-wrapped, post-wrapped, post-around
The most important thing is that each function in code will return a function and wait for one more parameter to activate the inner one.
So after wrap, the
pre-wrap function actually looks like this:
(fn [request] (str (identity request) ", post-wrapped"))
(fn [request] (str (pre-wrap request) ", post-wrapped"))
(fn [request] (str (post-wrap (str request ", pre-around")) ", post-around"))
After this, when we call
(handler "(Rugal Bernstein)"), of course it will be a invert order execution.
This is a good example for non-funtional programmer to think from the perspective of functional programming.
Try to understand it by yourself, you will learn more than just copying.