<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cristian Gabbanini on Medium]]></title>
        <description><![CDATA[Stories by Cristian Gabbanini on Medium]]></description>
        <link>https://medium.com/@cristian.gabbanini?source=rss-e9f500ebaed1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7KJc6UTi2xCB-g3Yz6jZzQ.jpeg</url>
            <title>Stories by Cristian Gabbanini on Medium</title>
            <link>https://medium.com/@cristian.gabbanini?source=rss-e9f500ebaed1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 11:45:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cristian.gabbanini/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Combinators]]></title>
            <link>https://codeburst.io/combinators-82799638c90d?source=rss-e9f500ebaed1------2</link>
            <guid isPermaLink="false">https://medium.com/p/82799638c90d</guid>
            <category><![CDATA[currying]]></category>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[combinator]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Cristian Gabbanini]]></dc:creator>
            <pubDate>Fri, 08 Jun 2018 14:16:58 GMT</pubDate>
            <atom:updated>2018-06-20T08:48:22.292Z</atom:updated>
            <content:encoded><![CDATA[<p>The friendliest birds you’ll ever meet (and they never poop on your shirt)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*e2W75j7OrXLIZkQjIP2zwA.jpeg" /></figure><p>If, like me, you are into functional programming, you have heard and heard of <em>composition.</em> Composition is definitely a must. It is one of those tools which we cannot build anything useful without (being <em>currying</em> its closest companion). Metaphorically speaking, I would say that if <em>Currying</em> is the Father, <em>Composition</em> is the Son of an hypothetical functional programming Trinity.<br>What perhaps you have not already met, or met under disguise, are <em>Combinators</em>, which I believe could be considered as the Holy Spirit of out Trinity (there’s no need to say that the first commandment is: “<em>Thou shalt be pure”</em>).</p><p>Combinators come from <em>Lambda calculus, </em>whose father, Alonzo Church, starting from some relatively simple <em>set of rules</em> and <em>operations</em>, managed to describe a <em>computation system</em> using just functions (unary functions to be clearer). And, for the sake of clarity, it must be noted that both <em>Lambda calculus</em> and <em>Touring machine</em> are considered to be equivalent. Generally speaking it means we can do (or describe) the exact same computation — and get the <em>same result</em> — using, on one hand, a more <em>imperative</em> approach and, on the other hand, a <em>declarative </em>one.</p><p>But it’s been since 1985, when Raymond Smullyan published its book <em>“To Mock a Mockingbird”, </em>that it has become a common habit to give combinators the name of birds. <br>First things first. Let’s start with a definition.</p><h4>What is a combinator</h4><p>From the <a href="https://wiki.haskell.org/Combinator">Haskell wiki</a>, the definition of a combinator is:</p><blockquote><em>A function or definition with no </em><a href="https://wiki.haskell.org/Free_variable"><em>free variables</em></a><em>.</em></blockquote><p>As a function it must be <em>pure</em>, and having no free variables it must refer only to the <em>its arguments</em>. There’s some debate on whether or not functions like <em>map</em> belong or do not belong to the category of combinators, and, for what I saw it depends in most cases from its implementations which are language or library specific.</p><p>Let’s put aside those querelles. What you must know is that combinators could look simple, they are, after all, one of the simpliest form of functions, but canexhibit very <em>complex</em> behaviours expecially when combined toghether.</p><p>Moreover they prove themselves useful in a sensible part of our everyday work.</p><h4>When to use combinators</h4><p>There are many cases in which the flow of operations of our programs <em>doesn’t follow a straight linear path</em>, either because we are forced to deal with external libraries that trigger some side effects, or because we are relying on some native functionalities (namely the DOM) which are heavily object oriented and have very little in common with the functional <em>milieu, </em>or because the logic of our applications requires so<em>.</em></p><p>In all those cases, the use of one ore more combinators can help not only to solve apparently <em>blocking</em> or <em>complex issues</em> where the inputs of our functions do not seem to fall right in place for composition, but can bear the additional benefit of making our c<em>ode clearer and more readable giving </em>us the opportunity to effectively <em>reuse</em> more code.</p><h4>Combinators examples</h4><p>Here follow some of the more frequently used combinators along with their lambda expression and their JavaScript counterpart and for every one of them I will show a typical – and hopefully practical – use case.</p><h4>Identity bird → <em>λa.a</em></h4><p>The identity bird, is a combinator which returns the argument it is provided with.</p><p><strong>Example:<br></strong> Let’s say we need to check if the total amount of a shop cart exceeds a particular threshold in order to <em>apply a discount</em> of say, 25%.<br>We want to apply the discount if, and only if, that threshold is exceeded. Otherwise we want to leave the amount of our cart unchanged.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b8be49d09ce80cee809b1704936e087/href">https://medium.com/media/7b8be49d09ce80cee809b1704936e087/href</a></iframe><p>In the previous case, we used the current combinator to represent all the cases in which we do not want to apply a discount. Notice that, to improve readability, we aliased our Identity function with the name <em>noDiscount.</em> Functional additional value with just one line of code.</p><h4>Identity Bird Once Removed → λab.ab</h4><p>This combinator is also know as <em>function application</em> as it easily can be thought as if the argument <em>b </em>was <em>applied to </em>function <em>a, i.e.: a(b)</em>.</p><p>Let’s imagine we are working for a company which sells vending machine that can be controlled through a smartphone so that, for example, we can have our coffee or our tee ready when we want, having to do nothing else than drinking it and taking a deserve pause from work. This beverages machine can serve different combination of beverages depending on the choice of the customer and, for each customer, we know the list of the available beverages in advance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86c32776fd23714cfc98671da6d839cb/href">https://medium.com/media/86c32776fd23714cfc98671da6d839cb/href</a></iframe><p>Using the <em>function application</em> combinator, we can pass the first argument our <em>serve</em> function is taking to our composition which, in turn , will choose the needed function to prepare the chosen beverage according to its quantity.</p><p>In this way we need only one function, <em>serveBeverages</em>, which, once “loaded” with all the available beverages (that in this case are hardcoded but could as well be fetched from a server) can serve every available drink with a single function call.</p><h4>Thrush → <em>λab.ba</em></h4><p>This combinator is very similar to the Identity bird once removed, in the sense that it applies and argument to a function, but, instead of taking first the function and then the argument, it takes <em>first the argument</em> and then the function.</p><p><strong>Example:<br></strong>Let’s say we need to toggle a button visibility depending on whether another element of the page is visible or not. For the sake of simplicity, let’s imagine that we have “subscribed” to a stream that, using the <em>IntersectionObserver</em>, calls our function every time something interesting happens passing as its entries as the argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45c5f2e24f4db90a569e9a00406764be/href">https://medium.com/media/45c5f2e24f4db90a569e9a00406764be/href</a></iframe><p>We take the first element of the entries array, read its property <em>isIntersecting</em> which returns a <em>boolean</em> value determining if the element we are interested in is on the screen or not.<br>Then, if the element is on the screen, we return the <em>addClass</em> function, on the contrary, if the element is not on the screen we return the <em>removeClass</em> function. <em>K</em>, is the <em>Kestrel </em>combinator which will talk about soon below. For now, its sufficient to say that it just returns the function we need to continue our computation.<br>Both <em>addClass </em>and <em>removeClass</em> take two arguments: the first argument is the class we want to add or remove, in this case is “hidden” and the second argument is the HTMLElement to apply this change to.<br>Here, our combinator, shows its usefulness twice.<br>The first time it applies the <em>String</em> <em>“</em>hidden” to <em>addClass</em>/<em>removeClass</em>. The second time, it applies the function resulting from the previous application to the destination <em>HTMLElement </em>(remember that in functional programming we almost always deal with <em>unary</em> functions, that is functions that take one argument only) thus hiding/showing it as requested.</p><p><strong>Example 2:</strong></p><p>Let’s imagine we’d like to exploit the native <em>reduceRight</em> method to create a <em>compose </em>helper. We could think that using the Thrush to perform each function call would be sufficient. Unfortunately our Thrush function is <em>unary </em>while the <em>reduceRight</em> function is <em>binary</em>. And that brings us to another common problem in functional programming, that is function inputs. In many cases, when we work with external libraries or native stuff we would be left with no weapons if we weren’t not able to make a unary function act as a binary one or vice versa. And this example shows this problem pretty clearly.</p><p>So, in order to make it work, we could create a binary helper which would take a function and 2 arguments passed in simultaneously and would call the function once per argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48e11c4cfaf7581419b3c39001701d31/href">https://medium.com/media/48e11c4cfaf7581419b3c39001701d31/href</a></iframe><p>The <em>binary </em>helper acts as an wrapper on Thrush <em>combinator </em>giving it the ability to act <em>as if</em> it was a binary function but still being unary.</p><h4>The bluebird → <em>λabc.a(bc)</em></h4><p>If you’re thinking this combinator looks familiar, you are absolutely right! In fact it resembles very closely the Son of our Trinity: <em>function composition</em>.</p><p><strong>Example:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5293cd9119052ae71305ff67211e79a/href">https://medium.com/media/f5293cd9119052ae71305ff67211e79a/href</a></iframe><p><strong>Example 2:</strong></p><p>We can use the Bluebird in every case when we must pass a list through a series of transformations (in this example we are provided with a list of numbers), transformations which can be composed together.<br>In case a compose utility is not available, we can express this sequence as a <strong>reduction of an array of functions</strong>, with one caveat: as the <em>Array.reduce</em> method is <em>binary </em>and the Bluebird is a <em>unary </em>function, we must place in between them an interface which will make our <em>Bluebird behave as if it was binary</em> (that is the purpose of the binary function);</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f8578a296aa19f479ef520d56f51358/href">https://medium.com/media/8f8578a296aa19f479ef520d56f51358/href</a></iframe><h4>The kestrel → <em>λab.a</em></h4><p>Every time it is called, the kestrel, aka <em>constant</em>, returns the first argument it was given.</p><p><strong>Example:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4069293205111e03215e7d5672f575b/href">https://medium.com/media/d4069293205111e03215e7d5672f575b/href</a></iframe><p>In the previous example we just use the <em>K</em> combinator to determine wheter it should or should not be visible.</p><p>Next to come….</p><h4>The kite → <em>λab.b</em></h4><h4>The starling → λabc.ac(bc)</h4><h4>The mocking bird → λa.aa</h4><p>Happy coding!</p><figure><a href="http://bit.ly/codeburst"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3hPOj27LTt0ZPn5TQuhZg.png" /></a></figure><blockquote>✉️ <em>Subscribe to </em>CodeBurst’s<em> once-weekly </em><a href="http://bit.ly/codeburst-email"><strong><em>Email Blast</em></strong></a><strong><em>, </em></strong>🐦 <em>Follow </em>CodeBurst<em> on </em><a href="http://bit.ly/codeburst-twitter"><strong><em>Twitter</em></strong></a><em>, view </em>🗺️ <a href="http://bit.ly/2018-web-dev-roadmap"><strong><em>The 2018 Web Developer Roadmap</em></strong></a><em>, and </em>🕸️ <a href="http://bit.ly/learn-web-dev-codeburst"><strong><em>Learn Full Stack Web Development</em></strong></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82799638c90d" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/combinators-82799638c90d">Combinators</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Composing the uncomposable]]></title>
            <link>https://codeburst.io/composing-the-uncomposable-23dbcd46940c?source=rss-e9f500ebaed1------2</link>
            <guid isPermaLink="false">https://medium.com/p/23dbcd46940c</guid>
            <category><![CDATA[monads]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[dom]]></category>
            <dc:creator><![CDATA[Cristian Gabbanini]]></dc:creator>
            <pubDate>Wed, 02 May 2018 13:00:12 GMT</pubDate>
            <atom:updated>2018-05-04T15:04:41.158Z</atom:updated>
            <content:encoded><![CDATA[<h4>The IO monad and the DOM</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*krgxRCIfjrHy-qqSo6KCkw.jpeg" /><figcaption>Monadic love</figcaption></figure><p>In the last few days, I’ve been experimenting with functional Javascript applied to DOM elements manipulation and, as strange as it initially seemed to me, I now think that’ now pretty feasible.</p><h4>Making HTMLElement composable</h4><p>One of the first problems I’ve encountered is <em>how to deal</em> with objects (mainly instances of HTMLElement) that, by their nature, are <em>not composable</em>, i.e., objects for which you cannot just write…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce3dff81aed5e09e046f05c30834041d/href">https://medium.com/media/ce3dff81aed5e09e046f05c30834041d/href</a></iframe><p>…and hope that it will work: it won’t!<br>Perhaps you could make the header background blue, but then you’d be thrown a disgraceful error:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a7fa0e42f9265534e4efced838a6d75/href">https://medium.com/media/6a7fa0e42f9265534e4efced838a6d75/href</a></iframe><p>That error arise from the fact that when we call <em>makeWhiteText</em>, its input is no longer an HTMLElement, since our <em>addClass </em>function, which relies on some native functionality, does not behave as we’d expect in a functional word. It does not return a DOM element: it returns <em>undefined.</em></p><p>What shall we do then? Is all the hope lost? <br>I don’t think so..</p><p>In fact, we could create a little helper function (which you will find in many of the functional libraries on the internet) called <em>constant</em> which will always return the first value it is passed.</p><p>This is, in fact, an alias for the famous <em>Kestrel </em>combinator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9f74747c77ad5342de5aa2121f6c79/href">https://medium.com/media/bf9f74747c77ad5342de5aa2121f6c79/href</a></iframe><p>Yes, it is simple as that! And now, with our new helper, we can solve our problem:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de406ab3178fbd0899852fc5e92b4362/href">https://medium.com/media/de406ab3178fbd0899852fc5e92b4362/href</a></iframe><h3>Waiting for the DOM to be ready</h3><p>In many cases, the approach you just saw will suffice. But what if the element we needed to modify hadn’t been put into the DOM yet?</p><p>Normally, we would add a <em>DOMContentLoaded</em> event listener which, in turn, would call our function at the right time.</p><p>In a functional environment, however, we cannot deal directly with impure functions as are those provided by the document object model. We have to wrap those functions with a monad, specifically an <em>IO monad,</em> which in return will gracefully give us a way to delay the triggering of all the side effects our unsafe code might spit out until we tell it to do so (aka to <em>run).</em></p><p>Moreover, being an <em>apply</em>, the IO monad allows us to…well, <em>apply </em>any value to its content and we know that the IO monad loves to hold functions. Remember that in Javascript functions can be passed as arguments too. This way we can create a <em>domReady</em> curried helper which takes a function and returns an IO that, once executed, will wait for the DOM to be ready and then will run the function we supplied.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df2eb2b681d64a330f5ce80082381124/href">https://medium.com/media/df2eb2b681d64a330f5ce80082381124/href</a></iframe><p>In the snippet above, I show you two implementations of the <em>domReady</em> helper which are equal, and by equal I mean: they do the same thing, only the syntax varies. <em>Lifting </em>a couple of values into a monad is a common operation in functional programming, therefore many of the Javascript libraries you will find out there will give you a couple of helpers to do this kind of lifting in a <em>pointfree</em> fashion (which in many cases is what I like the most). They are usually in named (<em>liftA2</em>, <em>liftA3 </em>where the cardinal number represents the number of values you want to apply).</p><p>As you may already have noticed, I am relying on the IO monad implementation provided by <strong>Crocks</strong> (<a href="https://github.com/evilsoft/crocks">https://github.com/evilsoft/crocks</a>) which is a library that definitely deserves a watch if you’re into <em>ADTs</em> and <em>functional programming</em>. Moreover, Ian Hoffmann Hicks, the guy behind evilsoft, has a nice You Tube channel (<a href="https://www.youtube.com/user/TheEvilSoft/about">https://www.youtube.com/user/TheEvilSoft/about</a>) that has more than a few videos about functional programming in Javascript, the majority of which deal with <em>monads</em>.</p><p>As a side note, I must specify that in the <em>_domReady</em> function I use the ternary operator just to show you how simple it is to rely on <em>third-party cross-browser</em> implementations of a DOM ready event listener (here I am using the one that comes with jQuery): you have simply to replace the code referencing <em>jQuery.ready() </em>with the function provided by the library of your choice.</p><h3>Putting it all together</h3><p>I think that now we have all that we need to bootstrap a simple application which, when DOM is ready, will perform a few basic things.</p><p>Our <em>domReady</em> wrapper will take care of transforming the function it is provided with into an IO that can safely be executed (the IO monads is <em>lazy</em>: you have to call <em>run</em> to unleash its side-effects).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab86cd4fd0c00fe4983c5aa476badf48/href">https://medium.com/media/ab86cd4fd0c00fe4983c5aa476badf48/href</a></iframe><p>Our <em>app</em> doesn’t really do anything fancy: it just gets the <em>header </em>and applies to it a couple of classes that alter its appearance (namely, they make its background color blue and its text color white).</p><p>This is, of course, a very simplistic example and nevertheless, at its roots, this is really everything that it takes to create a fully compositional Javascript application which, before starting, waits for the DOM to load. In the real world, we would most certainly need other monads to build something worth our efforts (Async/Task/Future, Maybe, Either and so on and so forth…), and we would work with nested types but, with respect to the foundations, we can faithfully assume that there won’t be any relevant differences.</p><p>Next time, we will work on a <em>carousel</em> app built upon this example which will leverage the power of other useful monads.</p><p>Happy coding!</p><figure><a href="http://bit.ly/codeburst"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3hPOj27LTt0ZPn5TQuhZg.png" /></a></figure><blockquote>✉️ <em>Subscribe to </em>CodeBurst’s<em> once-weekly </em><a href="http://bit.ly/codeburst-email"><strong><em>Email Blast</em></strong></a><strong><em>, </em></strong>🐦 <em>Follow </em>CodeBurst<em> on </em><a href="http://bit.ly/codeburst-twitter"><strong><em>Twitter</em></strong></a><em>, view </em>🗺️ <a href="http://bit.ly/2018-web-dev-roadmap"><strong><em>The 2018 Web Developer Roadmap</em></strong></a><em>, and </em>🕸️ <a href="http://bit.ly/learn-web-dev-codeburst"><strong><em>Learn Full Stack Web Development</em></strong></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23dbcd46940c" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/composing-the-uncomposable-23dbcd46940c">Composing the uncomposable</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ES6 curry snippet and a silly albeit common use case]]></title>
            <link>https://medium.com/@cristian.gabbanini/es6-curry-snippet-and-a-silly-albeit-common-use-case-abb46abc802f?source=rss-e9f500ebaed1------2</link>
            <guid isPermaLink="false">https://medium.com/p/abb46abc802f</guid>
            <category><![CDATA[currying]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Cristian Gabbanini]]></dc:creator>
            <pubDate>Fri, 20 Apr 2018 09:40:02 GMT</pubDate>
            <atom:updated>2018-04-30T18:49:15.772Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*TmCmikK1cmupMKFriwwv2w.png" /></figure><p>In the past days, and just for fun, I tried to do my own implementation of <em>currying </em>in ES6. Of course there are many of them out there, the majority of which is more robust and sounder than mine.</p><p>Anyway, there are some times when you might just want to <em>partially apply arguments</em> to a function withouth having to rely on external libraries. In such cases, the following snippet might help:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44eb34543b617457f68a7e54ff5b23f0/href">https://medium.com/media/44eb34543b617457f68a7e54ff5b23f0/href</a></iframe><p>Now, I have a confession to make: I’m not doing jQuery anymore…and yes, I’ve been in rehab for almost a year now and, except from when I just feel the need to spam a <em>$( “something” )</em> somewhere in my code — crazy cravings — I think I’ll definitely be jQuery free pretty soon (not that I have something in particural against jQuery or its users…addiction apart obviously).</p><p>And I have to admit that my <em>curry </em>companion up there and its big brother <em>compose </em>have been really useful friends in my journey (although I think that I am now becoming addicted to them…that’s worrying!) in my daily jQuery free chores.</p><p>This is <em>compose, </em>by the way, let’s give him a big “Welcome!”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e14be4ca924b40fd92cee9c680478dbd/href">https://medium.com/media/e14be4ca924b40fd92cee9c680478dbd/href</a></iframe><h3>A silly use case</h3><p>As it happens, there are countless times when we have to do DOM manipulations not having to rely on third party frameworks (I have nothing against them by the way). And we all know that those manipulations, so to speak, are tedious, redundant and, let’s be honest: <em>pretty boring</em>.</p><p>So, in an attempt to reduce the amount of redundant code I had to helplessly stare to in the past years (remember, always be <em>DRY</em>) and trying to spice it up a little bit I came up with the following code.</p><p>This is a very <em>basic example</em>, but I like how much we can get a cleaner and more readable code just by <em>currying </em>and <em>composing </em>functions together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16dca15ba98027d232117d8b3508f065/href">https://medium.com/media/16dca15ba98027d232117d8b3508f065/href</a></iframe><p>Since DOM elements do not compose well, I created an helper function called <em>tunnel</em>, which takes whatever input it is given and gives it back as it is.<br>As a final notice, I think we could improve the code above just by <em>memoizing </em>the getElement function, thus querying the DOM for the elements we need only once.</p><p>I’m sorry but, as it is usually said, that will be left to the fearless reader..</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abb46abc802f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>