In an impure language like Javascript you can render impure functions like Header pure by returning a description of the impure computation instead of running it. Then you can use functor to transform this description and monad to combine several descriptions:
constHeader=text=>()=>{consth1=document.createElement('h1');h1.innerText=text;document.body.appendChild(h1);returnh1;};// Functorconstmap=f=>tx=>()=>f(tx());// Monadconstchain=mx=>fm=>()=>fm(mx())();// MAINconstdata=Header("foo");constfoo=map(h1=>(h1.innerText=h1.innerText.toUpperCase(),h1))(data);constbar=chain(foo)(h1=>()=>(h1.innerText+="bar",h1));// no DOM update yetbar();// updates the DOM with "<h1>FOObar</h1>"
This way you can separate the pure realm of your program from the impure one.
In an impure language like Javascript you can render impure functions like
Headerpure by returning a description of the impure computation instead of running it. Then you can use functor to transform this description and monad to combine several descriptions:This way you can separate the pure realm of your program from the impure one.
This is great :)